Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

General C++ Question...

Posted on 1999-01-12
2
Medium Priority
?
208 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
[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 Comments
 

Accepted Solution

by:
mozack earned 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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 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.
Suggested Courses

688 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