1

Possible Duplicate:
How can I declare classes that refer to each other?

Below is my code in a .h file. Compiler will complain about having SP object in CPattern. I can't place SP's declaration above CPattern as it's also declaring CPattern object in it. How do I solve this? Thank you for your help!

class CPattern
{
public:
    CPattern(void);
    ~CPattern(void);

    SP & Create(void);
};


class SP
{
private:
    const CPattern*    pPat;
public:
    SP()
    {
    }
    ~SP()
    {
        // pointer no longer requried
        delete pPat;
    }    
};
Community
  • 1
  • 1
AvatarBlue
  • 47
  • 7

1 Answers1

3

Add class SP; at the top of your file. This is a forward declaration which tells the compiler what an SP is but doesn't describe its implementation.

Keith Randall
  • 22,985
  • 2
  • 35
  • 54