我有需要实现运营商==和返回类型是布尔类。我不确定下面的代码是实现它的正确方法。正确的方式
//MyTest.hpp文件
class Test {
public:
Test();
virtual ~Test();
int x,y;
bool operator==(const Test &v);
};
// MyTest.cpp file
bool Test::operator==(const Test &v) {
return (x== v.x) && (y==v.y);
}
即使代码编译为实现我们需要使用模板这种标准方式。 我应该用模板的方式实现类似下面的代码:
template <class T>
bool operator==(const T &v);
要使用模板是不是标准的方式。 – juanchopanza
你看过http://www.cplusplus.com/doc/tutorial/templates/吗? – OnlineCop
@juanchopanza - 我已编辑的示例代码.. – user1291401