0

Here's my code:

menuState.hpp

#ifndef MENU_STATE_HPP
#define MENU_STATE_HPP

#include "state.hpp"
#include <SFML/Graphics.hpp>

class MenuState : public State
{
    public:
        MenuState();

        static void create(StateListener* Parent, const std::string name)
        {
            MenuState* myState = new MenuState();
            myState->parent = Parent;
            Parent->manageState(name, myState);
        }

        void enter();
        void exit();
        void resume();
    private:

};

#endif // MENU_STATE_HPP

I'm getting an undefined reference to the constructor when I do MenuState* myState = new MenuState(); and I'm not sure why because MenuState::MenuState() comes before the create function in the class declaration.

EDIT: I'm also getting the same error to all my sfml functions.

Here's the exact build messages: http://pastebin.com/e819FhPj

I do have the sfml libraries linked and the header path set in my compilers search directories.

  • 2
    You're missing the definition/implementation, cupcake. – Captain Obvlious Jul 16 '13 at 19:06
  • [See this question.](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – chris Jul 16 '13 at 19:06
  • @CaptainObvlious, Sounds tasty. – chris Jul 16 '13 at 19:07
  • @chris it's the longer shelf life. – Captain Obvlious Jul 16 '13 at 19:07
  • menuState.cpp wasn't included in the codeblocks project, hence the error. Didn't notice that >. –  Jul 16 '13 at 19:15
  • I'm also getting the same error to all my sfml functions. Here's the exact build messages: http://pastebin.com/e819FhPj I do have the sfml libraries linked and the header path set in my compilers search directories. –  Jul 16 '13 at 19:33

2 Answers2

5

It is always best to show the exact text of the error, but my educated guess is, you are getting a linker error, not a compiler error. Have you actually implemented the constructor anywhere? I bet you haven't.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85
  • menuState.cpp wasn't included in the codeblocks project, hence the error. Didn't notice that >. –  Jul 16 '13 at 19:15
  • I'm also getting the same error to all my sfml functions. Here's the exact build messages: http://pastebin.com/e819FhPj I do have the sfml libraries linked and the header path set in my compilers search directories. –  Jul 16 '13 at 19:31
1

I'm not an experience C++ developer but it seems like MenuState constructor is declared but not defined. Replace MenuState(); with MenuState(){} should fix the error.

Rukshan Perera
  • 150
  • 2
  • 9