Solved

General C++ Question...

Posted on 1999-01-12
2
199 Views
Last Modified: 2010-04-02
Hello experts exchange

I have a C++ program like so:

header1.h
--------- cut
#ifndef FOO1H
#define FOO1H

#include "Foo2.h"
class Foo1
{ void Func (Foo2 *);
};

#endif

--------- end

header2.h
--------- cut
#ifndef FOO2H
#define FOO2H

#include "Foo1.h"
class Foo2
{ void Func (Foo1 *);
};

#endif
--------- end

--------- Then their respective cpp files with function definitions etc...

This is resulting in compiling errors, mainly "Syntax" errors.  Should this happen?  If so, how do I correct  it?  I can get around it by including (essentially) "Foo2.h" in "Foo1.cpp" and then taking a void * parameter instead, but this is messy.  I want a good solution.
0
Comment
Question by:IgorStravinsky
2 Comments
 

Accepted Solution

by:
mozack earned 50 total points
ID: 1181970
You have a circular dependency. You cannot have 2 header files include each other. This can be avoided by using a forward declaration.  i.e.

// header1.h
class Foo2;  // the actual definition will come in header2.h
             // notice there is no #include here
class Foo1
{
   void Func(Foo2*);
};
0
 

Author Comment

by:IgorStravinsky
ID: 1181971
Thanks, that has corrected my problem . I knew there was a way to do it!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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

19 Experts available now in Live!

Get 1:1 Help Now