Solved

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

Posted on 2006-11-23
3
162 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now