Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a class setup like this?

I have a class setup like this:

class b;

class a
{
    b var;
};

class b
{
    a var;
};

How do i make it work?

Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This setup, as it’s written, isn’t possible – an instance of a contains an instance of b, which in turn contains an instance of a, which then contains an instance of b, ad infinitum.

Instead, you need the classes to hold pointers to each other:

class a {
   b* b;
};

class b {
   a* a;
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading