How to Resolve Circular References
I have two classes, they both use pointers to each other. Each of the classes is definied in it's own header file for the module. How can I resolve this circular reference?
If the classes are ClassA and ClassB, right before the declaration of ClassA, put:
class ClassB;
This won't work if you do anything more than declare a pointer to it.
class ClassB;
This won't work if you do anything more than declare a pointer to it.
My suggestion would be to refactor your code to get rid of the cross-dependencies. There are several ways to accomplish this, I recommend reading a book about design patterns, or at least use google.
One way would be to break out an interface that both classes knows about (both classes #includes "MyInterface.h"), class A would implement (inherit) that interface, and class B would have an interface pointer to class A that it calls methods in.
One way would be to break out an interface that both classes knows about (both classes #includes "MyInterface.h"), class A would implement (inherit) that interface, and class B would have an interface pointer to class A that it calls methods in.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement