• Advertisement
Sign in to follow this  

Two classes which contain pointers that point at the other class (C++)

This topic is 2383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I would like to know how to make it so class A can have a pointer to an instance of class B while class B can have a pointer to am instance of Class A.

Ive tryed defining them in two files:

ClassA.h:

#include "ClassB.h"

class cA{
private:
cB* pointer;
};


ClassB.h:

#include "ClassA.h"

class cB{
private:
cA* pointer;
};


but get errors saying class B is undefined and it cant make a pointer.

Ive also tryed having both classes in the same file but that produces similar results, am I missing something realy obvious or is it imposible to create this sort of 'loop' structure?

Thanks in advanced for any help :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement