0

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?

2 Answers2

5

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.

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
1

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);
}
Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696