Sign in to follow this  

Correctly placing enum declarations in a multiple file problem

This topic is 4306 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

I'm having problems getting my enum's placed without having my compiler complain about linker error 2019 and 1120 So far, I have the following three classes (.h and .cpp for all): Board Piece PieceGeom My main function is going to reference Board and Piece. Board is going to reference Piece. Piece is going to reference PieceGeom I have three enum classes defined so far as well. 'Direc' which will be needed to be used in main and Piece 'Color' which will be needed in main, Board, and Piece 'Status' which will be needed in main and Board Now, I had no problem just using int to represent all of these, but it isn't superclear and should be done with enum anyway, so I'm trying to switch it over, but my compiler is hating me and my mis-coding ways (again). So here are the relevant sections from the header files:
// Board.h file

#include "piece.h"

enum Status { ST_LOST, ST_CONT, ST_LOCK, };

class Board
{
public:
        /**/
        // Gets the color of a block
	Color GetBlockColor( int = 0, int = 0) const;
        // Checks if a piece has landed.
        Status CheckLock( Piece & );
        /**/

private:
        /**/
        Color **B_Ptr; // Pointer to 2d population array
        /**/
};



// Piece.h file

#include "piecegeom.h"

enum Direc { DIREC_CW, DIREC_CCW };

enum Color { CO_EMPTY, 
             CO_RED, 
	     CO_YELLOW, 
	     CO_ORANGE, 
	     CO_BLUE, 
	     CO_GREEN, 
};

class Piece
{
public:
        /**/
private:
        /**/
	Color P_Color;
        /**/
};



PieceGeom is just an empty class so far, and I don't think it's relevant to the problem anyway. main isn't coded yet, but it will #include "piece.h" and #include "board.h" and use all three enum classes. My book is ever-so-helpful by having 'enum' covered in chapter 2 (4 chapters before OOP) and not used for the rest of the book. what am I doing wrong? Errorlog:
LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
Debug/Tetrisclone.exe : fatal error LNK1120: 1 unresolved externals


Thanks

Share this post


Link to post
Share on other sites
Your problem is that the main function that is going to reference these classes doesn't exist- The compiler is just complaining about main being undefined. The only thing I see wrong with your enum declarations in the trailing "," after the last enum... But that should only generate a warning.

Try defining a main function, even one that just returns 0, and it should go away.

[Edited by - The_Incubator on June 14, 2006 2:27:42 PM]

Share this post


Link to post
Share on other sites
Nope. Still getting the same errors.

The reason I'm pretty sure it's the enums is because if I just turn all of the Color, Status, and Direc into int and comment out the enum declarations, it builds fine.

Share this post


Link to post
Share on other sites
What about if you only comment out individual enums? Can you narrow down the problem to being caused by one of the 3? Really, none of this should give you the error you're seeing though, unless perhaps it means your main file simply isn't being compiled.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
What about if you only comment out individual enums? Can you narrow down the problem to being caused by one of the 3? Really, none of this should give you the error you're seeing though, unless perhaps it means your main file simply isn't being compiled.


It looks like it's the 'Color' enum that's doing it.

I read up on namespaces, so I'm trying to wrap them all up into one of them and see if that fixes it. I can just create a "blank" header file with the namespace declaration and no class definition, correct? Or do I put it in a .cpp file or does it matter?

It seems like a bizzare error to me too, but the thing builds fine without the enums, so I'm at a loss.

Share this post


Link to post
Share on other sites
Could it be a naming conflict? Maybe one of your enums is using the same name as a Windows declaration, and it's affecting the compilation. To see if this is the problem, make sure you include all system headers (windows.h, iostream, etc.) BEFORE including Piece.h, Board.h, etc. This way, if you're redefining symbols used by other headers, you won't affect them (since yours will be compiled after theirs). Also, you could just try renaming all your constants with a few underscores in front to check the same problem.

Share this post


Link to post
Share on other sites
I don't know how, what, where, or why, but after I scrapped the code, created a new console app, and recoded it, it seems to be working so far.

I must have had some preference variables mischecked or something.

Thanks for all of your help, everyone.

Share this post


Link to post
Share on other sites

This topic is 4306 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this