Possible Duplicate:
Difference between 'struct' and 'typedef struct' in C++?

Is there a difference between

typedef struct{
} mystruct;


struct mystruct{


4 Answers

yan On Best Solutions

In C, the syntax to declare a struct is struct mystruct var;, so developers often typedef an anonymous struct to make declaring as simple as mystruct var;. C++ allows you to define structs without the struct keyword, so the typedef is used less often.

Cat Plus Plus On

It's useless in C++. In C, it's because structs have their own namespace (you need to write struct T if you don't typedef to something else).

Diego Sevilla On

There is no real difference in C++.

Szabolcs On

This idiom is commonly used in C, where a struct variable would need to be declared as struct StructName myStruct, and StructName myStruct wouldn't work. It's not necessary in C++.