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

Is there a difference between

typedef struct{
....
} mystruct;

and

struct mystruct{
....
};

?

4 Answers

1
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.

1
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).

0
Diego Sevilla On

There is no real difference in C++.

0
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++.