I have a function d() in a derived class, which is to be called in a base class function b(). I tried to do this by making a virtual function with the same name in the base class(to satisfy the compiler and to enforce late binding). I will always be calling the b() using an object of derived class. But the problem is that compilation goes fine, but linker is returning an error:
undefined symbol <baseclass_name>::d in module main.cpp
the Weird thing is that d() is not even called in main.cpp. It is defined and called in another file.
I am stuck here. Can anyone give any possible explanations or suggest a better method?
(I need to call d() from base class or it will make my code even more bulky...)
You'll need to either implement the base-class version, or declare it pure virtual in the base class (or both), depending on whether it makes sense for the base class to implement it. All non-pure virtual function must be implemented, which is probably why you get that error.