我正在尝试在C++中实现通用包装器,以便能够比较两个东西。我已经按照以下方式完成了它:
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;
};
看起来我无法以这种方式重载'<'和'>'运算符,所以我想知道有什么办法可以解决这个问题。