Solved

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

Posted on 2006-11-23
3
161 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
Comment Utility
>>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
Comment Utility

thank you.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You're most welcome ;o)

Any more questions on this issue?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

  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 …
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 …
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…

771 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