Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calling a function that is declared in class01 in a function in class02 ?

Posted on 2006-11-23
3
164 Views
Last Modified: 2010-04-01

Any suggestions as to the syntax I should use for calling a function that is declared in class01 in a function that is declared within class02 ??

I've tried the following:

function();

But I get an undeclared identifier error ?

Do I need to put the class name in front of it ?
0
Comment
Question by:andyw27
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 18004641
>>Do I need to put the class name in front of it ?

If it is a static method - yes. Otherwise, you'll need an instance of the class like

void class01::foo()
{
  class02 c2;

  c2.function();
}

You can only directly access it if class01 is derived from class02, otherwise you'll always need an object. If the code in 'class02::function()' is needed in several places, I'd rather advise to take it out of class02 and make it a regular/global function rather than a member of class02.
0
 

Author Comment

by:andyw27
ID: 18004668

thank you.
0
 
LVL 86

Expert Comment

by:jkr
ID: 18008440
You're most welcome ;o)

Any more questions on this issue?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question