Operatrator []作为非静态函数

Spe*_*ber 0 c++ operator-overloading

码:

SchedulingItem operator[](Schedule obj,int el){
    return obj.OfVector().at(el);
}
Run Code Online (Sandbox Code Playgroud)

错误:

academia::SchedulingItem academia::operator[](academia::Schedule, int)' must be a nonstatic member function
     SchedulingItem operator[](Schedule obj,int el)

问题出在哪儿?

Lig*_*ica 5

问题是,正如消息所说,此函数必须是非静态成员函数.

这只是一个C++法则operator[].

相反,您已将其设为非成员或"免费"功能.