Whats the difference btw just struct and typdef struct?
Whats the difference btw just struct and typdef struct?
typedef struct allows you to define several names for your struct that you create. Here's an example of a normal struct:
Code://Regular struct declaration: struct Sprite{ int HP, MP, Defense, Attack; Sprite(); //Yada, yada. }; //Typedef struct declaration: typedef struct Sprite{ int HP, MP, Defense, Attack; Sprite(); //Yada, yada. } sprite, SPRITE, _SPRITE_;
That's true, but most of the time typedef is used because no one wants to type "struct" everytime they declare an instance of the struct.
Um . . . this is C.Code:struct Sprite{ /* ... */ Sprite(); //Yada, yada. };
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.