Whats the difference between doing:
andCode:typedef struct myStruct { int a; int b; };
They both seem to do the same thing and produce the same results:Code:typedef struct { int a; int b; } myStruct;
Code:myStruct ms; ms.a = 3; ms.b = 4;
This is a discussion on Basic Typedef question within the C++ Programming forums, part of the General Programming Boards category; Whats the difference between doing: Code: typedef struct myStruct { int a; int b; }; and Code: typedef struct { ...
Whats the difference between doing:
andCode:typedef struct myStruct { int a; int b; };
They both seem to do the same thing and produce the same results:Code:typedef struct { int a; int b; } myStruct;
Code:myStruct ms; ms.a = 3; ms.b = 4;
You don't need the typedef in the first case there.
Yes they are the same but the first one without the typedef is the preferred way in C++.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
You should be getting a warning for the first version. It doesn't actually typedef anything. If you replace the struct {} part with a simpler type, say "int," it would look like:
Which is meaningless, and I'm surprised it does compile at all (it does compile though, at least with VC9)Code:typedef int;
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}