Thread: Why do I keep getting this error?

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    16

    Why do I keep getting this error?

    Alright, still working on my program here. But I keep running into this error that says:

    tictac.obj : error LNK2001: unresolved external symbol "public: __thiscall TicTacToe::TicTacToe(void)" (??0TicTacToe@@QAE@XZ)

    Debug/ttt.exe : fatal error LNK1120: 1 unresolved externals"

    I have no idea what this means.

    Here is the part of my code where I think the problems are occuring: (Sorry, I don't know how to use the code tags)

    //Class Declaration
    class TicTacToe {
    private:
    enum Status { WIN, DRAW, CONTINUE };
    char board[3][3];
    public:
    TicTacToe();
    void makeMove(void);
    bool validMove( int, int );
    void printboard();
    bool xoMove( int ); // ¿Need this?
    Status gamestatus( void );
    };

    ...
    void TicTacToe::printboard()
    {

    cout<< " | | \n";
    cout<< "____|____|____ \n";
    cout<< " | | \n";
    cout<< "____|____|____ \n";
    cout<< " | | \n";
    cout<< " | | \n";
    }



    I'm a beginner w/ C++, so don't be surprised if a quote or something that missed. Thanks.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    267

    Re: Why do I keep getting this error?

    Originally posted by Rizage
    Code:
    ...
    TicTacToe();
    ...
    Here you declared the default constructor 'TicTacToe', but you didn't define it; Since it's a default constructor, when you create a 'TicTacToe' object, it's called... but it's not defined anywhere so you get that error.

    Just make a note to yourself that when you see a link error like that, it means you declared a function somewhere, used it, while never having defined it.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    One more thing...

    In the class declaration, I am having some trouble setting the information in the array. This works with the compiler, no complaint:

    //Class Declaration
    class TicTacToe {
    private:
    enum Status { WIN, DRAW, CONTINUE };
    char board[3][3];
    public:
    TicTacToe();
    void makeMove(void);
    bool validMove( int, int );
    void printboard();
    bool xoMove( int ); // ¿Need this?
    Status gamestatus( void );
    };


    However, when I try to declare values for the array by typing:

    char board[3][3] = {{'a','b','c'}, {'d','e','f'}, {'g','h','i'}};

    The compiler doesn't like it. Is this illegal?

    Also, could someone please tell me how to use the code tags so my posts won't be so messy? Thanks.

  4. #4
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    try
    Code:
    char Board[3][3] = 
    {   
        'a', 'b', 'c',
        'd', 'e', 'f',
        'g', 'h', 'i'
    };
    Also, when you post code, include it between the tags [ code ] and [ /code ] (sans the space between the brackets and the text).
    "Logic is the art of going wrong with confidence."
    Morris Kline

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    [code&#93;
    void TicTacToe::printboard()
    {
    cout<< " | | \n";
    cout<< "____|____|____ \n";
    cout<< " | | \n";
    cout<< "____|____|____ \n";
    cout<< " | | \n";
    cout<< " | | \n";
    }
    [/code&#93;

    Would appear as:

    Code:
    void TicTacToe::printboard()
    { 
    	cout<< " | | \n";
    	cout<< "____|____|____ \n";
    	cout<< " | | \n";
    	cout<< "____|____|____ \n";
    	cout<< " | | \n";
    	cout<< " | | \n";
    }
    Last edited by XSquared; 08-15-2002 at 02:23 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Rizage
    Guest
    I tried:

    Code:
    char Board[3][3] = 
    {   
        'a', 'b', 'c',
        'd', 'e', 'f',
        'g', 'h', 'i'
    };
    But the syntax error still remained. The compiler says that the syntax error is due to the bracket {. And another error stating:

    error C2334: unexpected token(s) preceding '{'; skipping apparent function body.

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    This worked fine for me (on Dev-C++ 4.9.5, and MSVC++ 6)

    Code:
    char Board[3][3] = { {'a', 'b', 'c'},
    		     {'d', 'e', 'f'},
    		     {'g', 'h', 'i'}};
    OR

    Code:
    char board[3][3] = { {'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}};
    Last edited by XSquared; 08-15-2002 at 02:34 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    OK, I think I see what you're trying to do now. From the MSVC++ help files:
    This error will occur only after another error and only for member functions defined inside their class.
    Are you trying to do this?
    Code:
    class TicTacToe { 
    private: 
       enum Status { WIN, DRAW, CONTINUE };
       char board[3][3] = 
       {   
           'a', 'b', 'c',
           'd', 'e', 'f',
           'g', 'h', 'i'
       };
     
    public:
       TicTacToe();
       void makeMove(void);
       bool validMove( int, int );
       void printboard();
       bool xoMove( int );
       Status gamestatus( void );
    };
    If so, you can't assign a value to a variable in the class declaration. You should assign a value to board in the class constructor.
    Code:
    class TicTacToe { 
    private: 
       enum Status { WIN, DRAW, CONTINUE };
       char board[3][3];
    
    public:
       TicTacToe();
       void makeMove(void);
       bool validMove( int, int );
       void printboard();
       bool xoMove( int );
       Status gamestatus( void );
    };
    
    TicTacToe::TicTacToe()
    {
       //assign values to board
    }
    "Logic is the art of going wrong with confidence."
    Morris Kline

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM