Archived

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

Another basic C++ question

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

In C, this is a way to define a struct so that you can refer to it thereafter in code without the struct keyword. In C++, the two methods are more or less identical. There''s very little reason to use this idiom in C++.


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

Share this post


Link to post
Share on other sites
Nothing really, not in c++ anyway. If I recall correctly, in the old days of C programming you had to typedef you structs if you wanted to declare more than one. For example



typdef struct //you don''t actually need _STR
{
char* str;
int numchars
}STR;

// now you can declare them as:

STR foo;
STR bar;

// but in c++ the following is the equivalent of the above:

struct STR
{
char* str;
int numchars
};




Share this post


Link to post
Share on other sites
The small difference is that the C way really screws things up if you want to do templated structs. You can indeed use either _STR or STR if you do it that way.


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

Share this post


Link to post
Share on other sites
There are also small differences in exported symbol names (only really important if you''re writing a linker), valid member function names (not important if you''re using the struct as POD) and namespace pollution.

Share this post


Link to post
Share on other sites