Hello, I'm trying to do this:
I've bolded the error producing line. It's a function that returns a static instance of the Play_State class, it is a singleton.Code:#include "stdafx.h" #include "Menu_State.h" #include "Play_State.h" #include "IO.H" void Menu_State::handle_events(State_Manager * state_manager) { result = IO::instance().get_input(); switch(result) { case 1: // play blackjack state_manager->change_state(Play_State::Instance()); /* if(players.size() == 0) { initialize_players(2); } pot = new Pot; deck = new Deck; deck->shuffle_deck(); players[0].draw(*(deck), 2); players[1].draw(*(deck), 1); return 3; case 2: // quit game return 4; default:// invalid entry std::cout << "Please enter 1 or 2.\n"; return 0; */ } }
I've done something similar to this before and never got a linker error, although I've never done this with a derived class before...Code:#ifndef PLAY_STATE_H #define PLAY_STATE_H #include "Gamestate.h" class Play_State : public Gamestate { public: void init(); void cleanup(); void handle_events(State_Manager * state_manager); void update(); void print(); static Play_State * Instance() { return &play_instance; } protected: Play_State() {}; private: static Play_State play_instance; }; #endif
Here is the Gamestate abstract class:
I'm getting error messages when trying to grab an instance of the Play_State.Code:#ifndef GAMESTATE_H #define GAMESTATE_H #include "State_Manager.h" class State_Manager; class Gamestate { public: virtual void init() = 0; virtual void cleanup() = 0; virtual void update(State_Manager * state_manager) = 0; virtual void print(State_Manager * state_manager) = 0; virtual void handle_events(State_Manager * state_manager) = 0; void change_state(State_Manager * state_manager, Gamestate * state); protected: Gamestate() { } }; #endif
Any ideas as to why this is happening?Code:------ Build started: Project: Blackjack, Configuration: Debug Win32 ------ Compiling... Menu_State.cpp Generating Code... Skipping... (no relevant changes detected) Play_State.cpp Linking... Menu_State.obj : error LNK2001: unresolved external symbol "private: static class Play_State Play_State::play_instance" (?play_instance@Play_State@@0V1@A) C:\Documents and Settings\jcoleman\Desktop\Blackjack\Debug\Blackjack.exe : fatal error LNK1120: 1 unresolved externals Build log was saved at "file://c:\Documents and Settings\jcoleman\Desktop\Blackjack\Blackjack\Debug\BuildLog.htm" Blackjack - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



LinkBack URL
About LinkBacks





