class SYMBOL : public std::string
{ // Bunch of SYMBOL specific attributes
protected:
virtual COMPARE_CC Compare (const SYMBOL & rhs) const;
...
From SYMBOL, I have a bunch of derived classes for different types of symbols.
1 2 3 4 5
class RSETNAME : public SYMBOL
{ OWNER m_owner;
COMPARE_CC Compare (const RSETNAME & rhs) const;
...
I'm getting the following error from the compiler:
rsetname.h(6,15) : warning (1319) : function "SYMBOL::Compare(const SYMBOL &) const" is hidden by "RSETNAME::Compare" -- virtual function override intended?
I understand what the error is telling me. What I'm not clear on is how to accomplish what I want to do. I'd like to be able to compare two objects derived from SYMBOL but which may or may not be RSETNAMES. If they are both RSETNAMEs, then use the RSETNAME::Compare function.
Any ideas? Please limit suggestions to C++03. I'm stuck on a C++03 platform and can not change that.
You do not want to use a virtual function for this. You need to create a custom override (as you are doing) in each class. Eliminate the "virtual" from the base class. It is not a virtual function.
As an aside, inheriting from std::string like this is ill-advised. The STL containers (including std::string) were not designed to be base classes and inherited from. They are "final". You can tell this because the destructors are not declared virtual.
I had it that way, but that wasn't accomplishing what I wanted.
What I want to do is compare two symbols and invoke the appropriate derived Compare function. I don't necessarily know the types of the symbols when I'm comparing them (nor do I want to). I was looking at polymorphism to do that for me.
The more I think about this, the more I think this is problematic. What if the left and right side are different derived types?
Thanks for the pointer on deriving from std::string. I wasn't aware the destructor wasn't virtual.
Only like things are comparable. Sounds like you have a bowl of fruit (base class) and you are comparing apples and oranges. If you need a different comparator for each type pair, you have a combinatorial problem that is orthogonal to your hierarchy.