-
Struct/typedefs
I have seen code like this in some places:
Code:
typedef struct _mystruct {
int x;
int y;
} mystruct;
But, in my C++ class at school, the teacher told us to do it like this (no typedef):
Code:
struct mystruct {
int x;
int y;
};
Why would you do the first one if the second one works?
-
In C, if you used:
Code:
struct <name> { // stuff };
You would have to declare variables of <name> like so:
Code:
struct <name> myVar;
When using the typedef, you eliminate the extra struct.
Z.
-
In C++, this weird syntax is no longer necessary. So it is absolutely understandable if your teacher tells you not to do it (it still works). But he should have told you why they did it otherwise in C.