0

I have the following code, and every time I compile, it's giving me an error saying that there is an undefined reference to ns::player::player()

This has never happened to me before, so to be honest, I'm quite confused. I just know it's something simple. By the way, the code below isn't exactly the code I'm working with, but it's the same idea. I just shortened it up and changed the names to make it easier to read.

Also, if I put it all into one file, it plays nice.

main.cpp

#include "space.hpp"
int main()
{
   ns::player kyle;
   return 0;
}

space.hpp

#ifndef SPACE_HPP_INCLUDED
#define SPACE_HPP_INCLUDED
namespace ns
{
   class player
   {
      private:
         int stat1, stat2, stat3;
      public:
         player();
         player(int, int, int);
   };
}
#endif

space.cpp

#include "space.hpp"
ns::player::player()
{
   stat1 = 100;
   stat2 = 200;
   stat3 = 300;
}
ns::player::player(int a, int b, int c)
{
   stat1 = a;
   stat2 = b;
   stat3 = c;
}
Kyle R.
  • 1,159
  • 2
  • 8
  • 5
  • 8
    Are you sure `space.cpp` is included in the build process? – Billy ONeal Dec 09 '12 at 08:16
  • Probably the same reason as [this question](http://stackoverflow.com/questions/13785695/using-static-class-in-c). – chris Dec 09 '12 at 08:17
  • 1
    I've actually just figured it out... I upgraded Code::Blocks yesterday, and for some reason, it unlinked all files from a project, and instead, just opened them and told me that they were linked. I removed them, and recreated the project with the same files, and wala. It works. I'm sorry to waste your time like this. – Kyle R. Dec 09 '12 at 08:24
  • 1
    @KyleR.: If you fixed the issue yourself, then you should delete this post, as it serves no purpose. – Nawaz Dec 09 '12 at 08:29
  • 2
    ...or answer your own question, so that others may learn from it. – johnsyweb Dec 22 '12 at 23:43

0 Answers0