Jump to content
  • Advertisement
Sign in to follow this  
haro

Forward Declarations to Typedefs?

This topic is 4665 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

Has anybody else noticed that VC++ in VS.NET 2003 will crash and burn if you try to use a forward declaration to a typedef'd type? You can test this out yourself. Create a main, and 2 others files. In one file create a blank struct called class1. In the other header file create a forward declaration for a class3 and then create a struct that only has one member, a class3 type. In the main file, include the class1 file and then setup the typedef class1 class3, and then include the class2 file. Create an instance of class2 in your main function and compile. You'll get the lovely fatal error C1001: INTERNAL COMPILER ERROR. This is really annoying and I'm currently looking for a workaround. Right now all I can figure is to either drop the typedef all together ( which is not an option ) or to use a preprocessor directive instead of a typedef, which will ruin intellisense and create just generally ugly code. As it stands, I'm having to drop the forward declarations which is annoying since it seriously bloats the compile time. Has this problem been fixed in the express versions? Any ideas on better workarounds?

Share this post


Link to post
Share on other sites
Advertisement
Are you complaining because it's crashing on valid code? Or is your code invalid? If the latter, explain what you're trying to do better...

Share this post


Link to post
Share on other sites
The code is valid and simple. Use a forward declaration to a typedef'd class and then instantiate the class that was using the forward declaration. It will not compile.

Share this post


Link to post
Share on other sites
Why not forward declare the class and then declare your typedef before you use it? If you do it that way, you shouldn't need to use a forward declared typedef.

Share this post


Link to post
Share on other sites
Do you mean something like this ?:

Class1.h

class Class1
{
} ;

Struct1.h

class Class 3 ;
struct Struct1
{
Class3 AMember ;
} ;

main.cpp

#include "Class1.h"
typedef Class1 Class3 ;

int main ()
{
Class3 AClass ;
return 0 ;
}

It compiles fine on my VS 2003.

Share this post


Link to post
Share on other sites
Quote:
Original post by Skeleton_V@T
...


Almost, change that to:

-- Class1.h
class Class1
{
} ;

-- Struct1.h
class Class3;
struct Struct1
{
Class3 AMember ;
};

-- Main.cpp
#include "Class1.h"
typedef Class1 Class3 ;
#include "Struct1.h"

int main ()
{
struct1 str;
return 0 ;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by nimrand
Why not forward declare the class and then declare your typedef before you use it? If you do it that way, you shouldn't need to use a forward declared typedef.


I'm not sure I exactly understand what you mean? If I do understand you, then declaring the class before I use it would completely bypass the purpose of the forward declarations - to speed up compile time. And there is also the issue that there is one typedef and multiple classes uses the typedef'd class. Again, maybe I'm not understanding what you're suggesting?

Share this post


Link to post
Share on other sites
Well you can't declare a member to be an incomplete type. And I can't imagine why you would want to typedef a class to the name of another class, nor could I think of what it might do, if any compiler allows it.

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
Well you can't declare a member to be an incomplete type. And I can't imagine why you would want to typedef a class to the name of another class, nor could I think of what it might do, if any compiler allows it.


Class3 is not an 'incomplete' type or an independant class; it is an alias for class1.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!