我有一个使用模板的自定义类,如下所示:
template<class T>
class foo
{
public:
T a;
bool operator<(const foo<T> &f);
//other functions...
}
template<class T>
bool foo<T>::operator<(const foo<T> &f)
{return a - f.a;}
现在,我新建了一些 foo 并赋予它们价值,然后我想对这个数组进行排序:
foo<int>* fp = new foo<int>[3];
//give each element value
sort(fp, fp+3); //run-time error
当我使用排序功能时,出现运行时错误。
我做错什么了吗?请帮我。