操作员[]作为非静态功能 [英] Operatrator [] as non-static function

查看:54
本文介绍了操作员[]作为非静态功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

SchedulingItem operator[](Schedule obj,int el){
    return obj.OfVector().at(el);
}

错误:

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

问题出在哪里?

解决方案

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

对于operator[] 来说,这只是C ++的法则.

您改为使它成为非成员或免费"功能.

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.

这篇关于操作员[]作为非静态功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆