-2

I have two classes.

First A.h

#ifndef A_H
#define A_H

#include "B.h"

class A
{
public:
    A(B* pair) :myPair(pair){};
    void checkPair();
private:
    B* myPair;
};

void A::checkPair()
{
    myPair->checkPair();
}

#endif

Second B.h

#ifndef B_H
#define B_H

#include "A.h"

class B
{
public:
    B(A* pair) :myPair(pair){};
    void checkPair();
private:
    A* myPair;
};

void B::checkPair()
{
    myPair->checkPair();
}

#endif

The Compiler tells me that he can't identify class A in B.h file. Is there any solutions for cyclic inclusion problems like this?

haksist
  • 229
  • 2
  • 5
  • 17

1 Answers1

1

In A.h file instead of including B.h use forward declaration:

class B;