Code:
SchedulingItem operator[](Schedule obj,int el){
return obj.OfVector().at(el);
}
Error:
academia::SchedulingItem academia::operator[](academia::Schedule, int)' must be a nonstatic member function
SchedulingItem operator[](Schedule obj,int el)
Where is the problem?
The problem is that, just as the message says, this function must be a non-static member function.
That's simply a law of C++, for operator[]
.
You've instead made it a non-member, or "free" function.
operator[]
must be a non-static member of your Schedule
class, eg:
class Schedule
{
private:
std::vector<SchedulingItem> m_vec;
public:
SchedulingItem& operator[](int el);
};
SchedulingItem& Schedule::operator[](int el)
{
return m_vec.at(el);
}