• Advertisement
Sign in to follow this  

Forward declarations don't work in VC++ 2005 express?

This topic is 4680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ahh this is driving me nuts! i am doing exactly this same file setup ... clicky! and i get an error saying that i'm using an undefined class when i try and use the forward declared class. like ... class ForwardDeclared; class Something { ForwardDeclared fd; // <---- ERROR }; is there some option that doesn't allow me to do this in vc++ ?

Share this post


Link to post
Share on other sites
Advertisement
You can only use pointers or references to a forward declared class before it's full declaration. It's always been this way.

Share this post


Link to post
Share on other sites
You can only forward declare pointer vars, not stack variables as the compiler needs to konw the size of the class and how to intantiate it if its a stack member variable.

THe compiler isn't broken.

You can do this:


class Something {
ForwardDeclared* fd; // <---- ERROR
};

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by DrZoidberg
class ForwardDeclared;

class Something {
ForwardDeclared fd; // <---- ERROR
};


And how, pray tell, will it know the size of ForwardDeclared in that code right there? ForwardDeclared is an incomplete type, and thus you may only have references or pointers to it as members.

Share this post


Link to post
Share on other sites
oh jesus, i feel like a moron ... i forgot to declare the variable as a pointer as i wanted, and thought i was declaring as a pointer. ahhhhh this is one of those 'duh' moments.

thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement