Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

751 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