Jump to content
  • Advertisement

Archived

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

tifkagh

Compiler can't find my constructor

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

My struct is defined as follows in a header Globals.h:
  
#if !defined _ICOORD
#define _ICOORD
typedef struct _iCOORD {
int X;
int Y;
_iCOORD(): X(0), Y(0) {};
_iCOORD(int &iInit): X(iInit), Y(iInit){};
_iCOORD(int &_X, int &_Y): X(_X), Y(_Y){};
~_iCOORD(){};
} iCOORD, *LPiCOORD;
#endif // _ICOORD

  
Globals.h is included in another file called Game.h. However when I define a variable of type iCOORD within Game.h I get the following error: compiler generated default constructor required by unnamed class The error then disappears when I comment out the definition of iCOORD. What is really weird is that I use the iCOORD structure at other points in my program and it works fine. What''s going on? tifkagh

Share this post


Link to post
Share on other sites
Advertisement
  
#ifndef _ICOORD
#define _ICOORD

typedef struct _iCOORD {
int X;
int Y;
_iCOORD(): X(0), Y(0) {}
_iCOORD(int &iInit): X(iInit), Y(iInit){}
_iCOORD(int &_X, int &_Y): X(_X), Y(_Y){}
~_iCOORD(){}
} iCOORD, *LPiCOORD;
#endif // _ICOORD



You shouldn''t be putting semicolons at the end of function definitions

Share this post


Link to post
Share on other sites
If you''re using C++, you do know that all that typedef stuff is unnecessary, yes? Just call the struct iCOORD and simplify your code. (Leave the typedef for LPiCOORD if you like.)

I can''t see any obvious errors (apart from the dubious-looking #if !defined bit), but maybe removing the semicolons as suggested by Vlade will help.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites
quote:
Original post by Kylotan
If you're using C++, you do know that all that typedef stuff is unnecessary, yes? Just call the struct iCOORD and simplify your code. (Leave the typedef for LPiCOORD if you like.)



quote:

I can't see any obvious errors (apart from the dubious-looking #if !defined bit), but maybe removing the semicolons as suggested by Vlade will help.



Tried that, no joy but I did take a look at the definition of the instance. It reads as follows:

    
#ifndef GAME_GLOBALS_OWNERSHIP
extern
#endif

struct
{
// In Game BOBs

lpBOB mousepointer;
lpBOB sheep;
lpCharacter player;
lpGSTATE gstate;
iCOORD test;
} GameG ;


Would it be the extern keyword that is causing my misery?

tifkagh

Edited by - tifkagh on February 17, 2002 8:33:16 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!