namespaces
-
filename: cat.h #include "dog.h" namespace Mammal { namespace Dog { class Collie { void virtual init( Mammal::Cat::Siamese *siamese ); } } } filename: dog.h #include "cat.h" namespace Mammal { namespace Cat { class Siamese { Mammal::Dog::Collie *collie; ... } } }
If I try to compile this, I get an error that says "Siamese is not a member of Mammal::Cat Any ideas why? -
filename: cat.h #include "dog.h" namespace Mammal { namespace Dog { class Collie { void virtual init( Mammal::Cat::Siamese *siamese ); } } } filename: dog.h #include "cat.h" namespace Mammal { namespace Cat { class Siamese { Mammal::Dog::Collie *collie; ... } } }
If I try to compile this, I get an error that says "Siamese is not a member of Mammal::Cat Any ideas why?1. You have the two classes (Siamese and Collie) dependant on each other which even if it works is poor practice. 2. Siamese has no functions defined. Elaine :rose: The tigress is here :-D
-
1. You have the two classes (Siamese and Collie) dependant on each other which even if it works is poor practice. 2. Siamese has no functions defined. Elaine :rose: The tigress is here :-D
I know it's a circular dependancy, and I promise I'll do penance for that. But that wouldn't account for the compiler not finding Siamese in the Mammal::Cat namespace. And there is more to each class, but these are the lines that I've narrowed down as the most likely candidates for causing the problem. As far as I can tell, the namespaces are set up properly, and Visual Studio has no problem parsing them to generate the class view or to generate the drop-down list for the auto-complete feature, but the compiler won't compile it, claiming that the Siamese class is not a member of that namespace.
-
I know it's a circular dependancy, and I promise I'll do penance for that. But that wouldn't account for the compiler not finding Siamese in the Mammal::Cat namespace. And there is more to each class, but these are the lines that I've narrowed down as the most likely candidates for causing the problem. As far as I can tell, the namespaces are set up properly, and Visual Studio has no problem parsing them to generate the class view or to generate the drop-down list for the auto-complete feature, but the compiler won't compile it, claiming that the Siamese class is not a member of that namespace.
May be you could try forward declaration. like namespace Mammal { namespace Cat{ Class Siamese;} } then, the actual dog namespace then, the actual cat namespace. Sonork 100.41263:Anthony_Yio