Hi,
Why would one write something like
... instead ofCode:typedef struct tagSTRUCT { int n; } StructName;
What's the deal?Code:struct StructName { int n; };
Hi,
Why would one write something like
... instead ofCode:typedef struct tagSTRUCT { int n; } StructName;
What's the deal?Code:struct StructName { int n; };
Because the first can be used as
while the second must be used asCode:StructName foo;
Code:struct StructName foo;
Other examples while combining both methods:
Code:typedef struct { int a; } a; typedef struct b { int b; } b; int main(void) { a struct_a; b struct_b; struct b struct_b2; struct_a.a = 0; struct_b.b = 0; struct_b2.b = 0; return 0; }
Hi,
Thanks for your almost immediate replies. But this compiles perfectly:
I don't need to type:Code:#include <iostream> struct s { int a; }; int main () { s _s; std::cout << _s.a << std::endl; return 0; }
struct s _s;
Why is that? I'm using Dev-C++ (the latest version) with the MingW compiler.
That's because you're using C++, not C, and you don't need to typedef structs in C++.
Using a C++ compiler actually. C++ supports some things that are not supported in C and a lot of ostensible C compilers in use are actually C++ compilers.
You might also try looking for compiler options (eg command line settings) to make your compiler behave as a C compiler rather than as a C++ compiler. To do that, it is necessary to read the documentation for your compiler.
I thought iostream, cout and endl were C++.
In C you need the typedef for convenience. In C++ you don't need it all (but the compiler accepts this syntax too).
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.