代码:
-
错误:
academia::SchedulingItem academia::operator[](academia::Schedule, int)' must be a nonstatic member function SchedulingItem operator[](Schedule obj,int el)
问题出在哪里?
答案 0 :(得分:5)
答案 1 :(得分:1)
operator[]
必须是Schedule
类的非静态成员,例如:
class Schedule
{
private:
std::vector<SchedulingItem> m_vec;
public:
SchedulingItem& operator[](int el);
};
SchedulingItem& Schedule::operator[](int el)
{
return m_vec.at(el);
}