【发布时间】:2020-11-24 00:55:15
【问题描述】:
让我更清楚地提出这个问题。
我有一个 Datarow 对象:
Class Datarow {
private:
vector<string> vals;
public:
std::string getVal(int index); //returns vals.at(index)
};
我有一个保存数据行的 Section 对象:
Class Section {
private:
vector<Datarow> rows;
public:
//Section methods
};
我有一个重载:
inline friend std::ostream& Section::operator<<(std::ostream& os, const Section& sec)
{
for(auto& row : sec.rows) {
if( sec.row.getVal(0) == "Tom" ) //<-- error here, c++ doesnt like me calling any method of
os << row << endl; // "row", since sec is const
}
}
假设我们也为 Datarow 重载了
【问题讨论】:
标签: c++ class constants operator-overloading accessor