Solved

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

Posted on 2006-11-23
3
167 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
[X]
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
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

636 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