1

I have a test class, it has nothing in it apart from the bones of a class.

h:

#ifndef TEST_H_
#define TEST_H_


class Test
{
public:
    Test();
};

#endif /* TEST_H_ */

cpp

#include "test.h"

Test::Test()
{
}

And then in my main class I have:

Test *test = new Test();

I also include test.h.

I get the error:

 Undefined reference to Test::Test()

Can anyone tell me where i'm going wrong?

emartel
  • 7,712
  • 1
  • 30
  • 58
panthro
  • 22,779
  • 66
  • 183
  • 324
  • 7
    You're not linking your implementation and you're using an unnecessary pointer with unnecessary dynamic memory allocation. C++ also has no main class, it has a `main` function. – chris Dec 15 '12 at 19:56
  • In my main class, the class that calls test, it is linked to other classes – panthro Dec 15 '12 at 20:02
  • @chris could you elaborate "You're not linking your implementation" – panthro Dec 15 '12 at 20:04
  • How do you compile/link it? And again, there's but one class here, and that's `Test`. – chris Dec 15 '12 at 20:04
  • Ok, so it's in an IDE. I'd wager you haven't put all three files into a project. – chris Dec 15 '12 at 20:06
  • possible duplicate of [gcc linker errors on fedora: undefined reference](http://stackoverflow.com/questions/12376897/gcc-linker-errors-on-fedora-undefined-reference) – Bo Persson Dec 15 '12 at 20:07
  • @ chris, they are in a project – panthro Dec 15 '12 at 20:07

1 Answers1

0

Figured it out, even after cleaning the project and restarting the IDE it still wouldn't work. I had to manually add in test.h and test.cpp to my config.pri

panthro
  • 22,779
  • 66
  • 183
  • 324