c++ - How to test a pure-virtual class without implementation? -
i have following class:
// ivirtualcontroller.hpp class ivirtualcontroller { public: virtual inputcode validate(int keycode) = 0; virtual ~ivirtualcontroller(); };
and want mock class:
// inputmanagertest.cpp class mockcontroller : public ivirtualcontroller { public: mock_method1(validate,inputcode(int keycode)); };
but doesn't work! following errors:
test/input/inputmanagertest.o: in function
mockcontroller::~mockcontroller()': test/input/inputmanagertest.cpp:19: undefined reference to
ivirtualcontroller::~ivirtualcontroller()' test/input/inputmanagertest.cpp:19: undefined reference `ivirtualcontroller::~ivirtualcontroller()'test/input/inputmanagertest.o: in function
ivirtualcontroller::ivirtualcontroller()': test/input/../../src/input/ivirtualcontroller.hpp:14: undefined reference to
vtable ivirtualcontroller'test/input/inputmanagertest.o: in function
mockcontroller::mockcontroller()': test/input/inputmanagertest.cpp:15: undefined reference to
ivirtualcontroller::~ivirtualcontroller()'test/input/inputmanagertest.o:(.rodata._zti14mockcontroller[_zti14mockcontroller]+0x10): undefined reference `typeinfo ivirtualcontroller'
a search told me "undefined reference vtable/typeinfo" errors caused missing implementation, missing "= 0" behind virtual method declaration or non-virtual destructor. class ivirtualcontroller isn't implemented, shouldn't problem since mockcontroller implementing it, right? commenting out whole inputmanagertest.cpp mock file "solves" problem, though ivirtualcontroller used in class.
how test it?
nope. destructor must implemented. pure virtual one.
that's because of how works. virtual
applied destructor holds a different more meaning. usually, virtual
method isn't called if it's overriden in derived class, virtual
destructor still called, implementation required.
the =0
destructor makes class abstract, but, stated before, implementation still required.
Comments
Post a Comment