I’m trying to implement generic wrapper in C++ that will be able to compare two things. I’ve done it as follows:
template <class T>
class GameNode {
public:
//constructor
GameNode( T value )
: myValue( value )
{ }
//return this node's value
T getValue() {
return myValue;
}
//ABSTRACT
//overload greater than operator for comparison of GameNodes
virtual bool operator>( const GameNode<T> other ) = 0;
//ABSTRACT
//overload less than operator for comparison of GameNodes
virtual bool operator<( const GameNode<T> other ) = 0;
private:
//value to hold in this node
T myValue;
};
It would seem to be I can’t overload the ‘<‘ and ‘>’ operators in this way, so I’m wondering what I can do to get around this.
Your operator functions are accepting their arguments by copy. However, a new instance of GameNode can not be constructed because of the pure virtual functions. You probably want to accept those arguments by reference instead.