How can I declare classes that refer to each other?

Posted by Without me Its just Aweso on Stack Overflow See other posts from Stack Overflow or by Without me Its just Aweso
Published on 2010-03-23T20:52:34Z Indexed on 2010/03/23 21:03 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

It's been a long time since I've done C++ and I'm running into some trouble with classes referencing each other.

Right now I have something like:

a.h

class a
{
  public:
    a();
    bool skeletonfunc(b temp);
};

b.h

class b
{
  public:
    b();
    bool skeletonfunc(a temp);
};

Since each one needs a reference to the other, I've found I can't do a #include of each other at the top or I end up in a weird loop of sorts with the includes.

So how can I make it so that a can use b and vice versa without making a cyclical #include problem?

thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about class