As already suggested to me, a forward declaration doesn´t seem to work. If I insert it in file "class_A.h" then the compiler does not know the member function class_B::funct, and if I insert it in file "class_B.h" the compiler does not know the object class_A.
Hello, I would like to know how I could solve the following circular dependency.
- You could remove the need for a friend declaration.
- You could make the entire class_B a friend of class_A.
- You could class_B::temp a pointer to class_A and only include "class_A.h" in the cpp file for class_B.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
The first option is mandatory, so I cannot change it.
The second is what I was trying to avoid.
And the third is the only option left, so I guess I'll do this way. I just wanted to know if there was any other option.
The problem I see is that it breaks the encapsulation of the classes,
The position of Bjarne Stroustrup (inventor of C++) on this issue is that a shared implementation doesn't weaken the encapsulation of the classes involved. (See The Design and Evolution of C++ in section 2.10 The Protection Model on page 53.)
But if you feel it does then you shouldn't use friend at all.
Last edited by nuzzle; June 21st, 2011 at 11:32 PM.
Bookmarks