【发布时间】:2014-03-13 22:20:05
【问题描述】:
所以我创建了一个名为 Tuples 的新类,其中 Tuples 接受一个称为 tupleVector 的字符串向量。然后我创建了一组元组,这意味着我需要重载对元素进行排序所需的运算符并禁止重复。
两个问题:
- 需要哪个运算符重载?我是否超载
-
假设我必须在我的 Tuples 类中执行此重载(以便我可以在其他类中使用 Tuples 集),以下代码是否正确?
include "Tuples.h" Tuples::Tuples(vector<string> tuple){ tupleVector = tuple; } vector<string> Tuples::getStrings() { return tupleVector; } bool Tuples::operator<(Tuples& other){ return this->tupleVector<other.tupleVector; } bool Tuples::operator==(const Tuples& other)const{ return this->tupleVector==other.tupleVector; } Tuples::~Tuples() { // TODO Auto-generated destructor stub }
【问题讨论】:
-
Tuples这个名字听起来像一个Tuples实例代表一组元组。
标签: c++ set overloading operator-keyword