I am somewhat surprised that the typedef is legal, since I thought shadowing was only for names with different scopes. I wonder if that line supported some crappy, pre-standard compiler that didn't obey C++'s rule that user defined types are treated like built in types.
You can use pointers or references to a forward declared type without having the definition available. You can't use their members (data or methods), but you can store and pass the pointers. So it's possible that the existing code that successfully uses the class with only the header's forward declaration is just manipulating pointers to it without ever trying to access members. On the other hand, if your code tries to access members, construct, destruct, declare an array of, instantiate a template using--or a few other things I can't think of--the class, then it would require the class definition to be visible in the compilation unit or it would fail to compile. I can't think of any scenario where it would compile with just a forward declaration but not link.
I don't understand the rationale you provided, unless it again dates to a pre-standard compiler. This should be legal without a forward declaration:
Code: Select all
class Foo
{
Foo *otherFoo; // Foo & otherFoo; would also be legal, but Foo foo; would not be.
void doFoo(Foo *);
};
I feel like I just beat a kitten to death... with a bag of puppies.