Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2652 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:


#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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!