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


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 ?
andyw27Asked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
>>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
 
andyw27Author Commented:

thank you.
0
 
jkrCommented:
You're most welcome ;o)

Any more questions on this issue?
0
All Courses

From novice to tech pro — start learning today.