I am trying to create a class that serves as a base object, which will then be subclassed (= implemented) to serve various purposes.
I want to define one or more pure virtual functions, so be that as it may, subclasses of the base class are necessary and don't forget to implement them.
There is one caveat, the pure signature of a virtual function includes the type of the base object. After the subclass, the definition of the function, of course, does not match the definition of the base classes. For instance:.
class BaseItem { public: virtual std::string getDifferences(const BaseItem& item) = 0; }
So, in a derived class, I would like to do:
class DerivedClass : public BaseItem { public: virtual std::string getDifferences(const DerivedClass& item) = 0; private: std::string derivedItemCustomObject; }
which, of course, the compiler will not accept. I could do it with BaseItem , of course, but then I cannot use any objects in the derived class.
Should casting be used to accomplish this?
Please let me know if my intention / question is not clear.
source share