Sign in to follow this  

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

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:

#include "ClassB.h"

class cA{
cB* pointer;

#include "ClassA.h"

class cB{
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this