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开发者_Go百科._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?
I think you forgot to put the class qualifier in the .cpp implementation. It should probably read:
void Engine::handleEvent() { ... }
I'd say deus-ex-machina399 probably has it right, but it could also be your calling conventions (would have to be different compiler settings between at least 2 different .cpp files). Try using __cdecl
or __stdcall
(or whatever the correct name is for the g++ compiler, try looking at this list)
精彩评论