Search code examples
c++functionheadervirtual

Class in header file


I'm having a bit of trouble with a C++ program I'm working on. I've created an abstract class with a single pure virtual method. Since the class has no variables or implemented methods, I've stored the class in a header file without an .cpp implementation file (there isn't any need for one).

The method is:

virtual void handleEvent() = 0;

The issue is when I inherit from that class and implement the method:

virtual void handleEvent(); (.h file)
void handleEvent(){.....} (.cpp file)

I get a compiler error (using g++):

(.rodata._ZtV10Engine[vtable for Engine]+0x8): undefined reference to Engine::handleEvent()

The file is being included in the Engine header class. Any ideas why this isn't working?


Solution

  • I think you forgot to put the class qualifier in the .cpp implementation. It should probably read:

    void Engine::handleEvent() { ... }