Archived

This topic is now archived and is closed to further replies.

Typedef problem

This topic is 5467 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all, I have a problem when wreiting the sorce of a member function. When I try to comple the code it has a syntax error with the line befor the ''*'' FACE * DisplayObjects::getFaces(int type); I had assumed that since I had decleared FACE type before the method I would be OK. I can''t seem to see anyother way. Thanks in advnce. (applogies about the code insersion). =============Header Code=============================== #ifndef DISPLAYOBJECTS_H #define DISPLAYOBJECTS_H #include <allegro.h> class DisplayObjects { private: * This is used to store the four veticies that make a face which make up * the cubes. */ typedef struct FACE { int v1, v2, v3, v4; } FACE; FACE faces1[18]; public: // class constructor DisplayObjects(); /** * Returns the faces index array for the tive requested. */ FACE * getFaces(int type); // class destructor ~DisplayObjects(); }; #endif // DISPLAYOBJECTS_H =============Header Code End =============================== =============Src code==================================== FACE *DisplayObjects::getFaces(int type) { if (type==1) return faces1; } =============Src code END====================================

Share on other sites
I usually don''t put the typedef statements in the class declaration. I don''t know if that''s because it doesn''t work that way or if it''s just my coding style.

Share on other sites
quote:
* This is used to store the four veticies that make a face which make up
* the cubes.
*/

All I can see is that your comment is missing an '/'

Regards Mats

Edit: One more thing...

You don't need the typedef.
struct FACE{  int v1, v2, v3, v4;};

[edited by - Matsen on March 8, 2003 10:04:13 AM]

Share on other sites
Thanks guys,

It seems that if I keep the ''typedef'' and make it global it works, well it complies.

My applogies about the coding, it was a cut and paste job, as ther is a lot more code that would have clutter up the post.

Thanks again.

Share on other sites
From what I see. Correct me if I am wrong but you can''t declare a struct variable inside your class definition. Thats what constructors are for. You should take face out of the struct definition. Thats my take. Maybe I am wrong?

Share on other sites
GGamer, since the struct is defined within the class DisplayObjects, you''ll probably need to type DisplayObjects::FACE instead of just FACE in your function...

MARS_999, GGamer wasn''t declaring an instance of the variable, he was just typedefing it, which is valid.