Archived

This topic is now archived and is closed to further replies.

typedef

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

Anybody: Is there any difference between:
struct StructTypeName{
   ...
};
 
or,
typedef struct{
   ...
} StructTypeName;
 
Doesn''t the first do implicitly what the second does explicitly? peace and (trance) out Mage

Share this post


Link to post
Share on other sites
In C, the second one allows you to refer to the type without using "struct". In C++, they are identical.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Well, they''re slightly different in C++.

The first reason is that typedef form cannot declare a constructor.

The second reason is that it becomes illegal in the second form to reference the type like:
struct StructTypeName * ptr;

Share this post


Link to post
Share on other sites