I have read a few things about forward declaration from previous posts. I see that references and pointers can be used with forward declaration but not objects, probably due to the fact that the compiler won't know some details of the class (like the size).
But this doesn't compile:
The errors (gcc):Code:class A { void fun(B& bclass) { bclass.data; } }; class B { int data; A hey; }
error: Invalid use of undefined struct B
error: forward declaration of struct B
Is there a way to do what I want?
Another question is this. Is dynamic_cast generally recommended to be used, or does it have to much an cost? Can its exception (wrong casting) be handled so the program doesn't crush?
And finally, lets say you have a pointer to a class A. You point it on a derived class B : A. Can you determine with a function if the pointer points at a class of a or B?



LinkBack URL
About LinkBacks




