一个函数重载问题

来源:互联网 发布:mac ps2017怎么破解 编辑:程序博客网 时间:2024/05/29 11:56

今天下午在看c++ primer plus时遇到一个疑问

请教个问题,一个类的2个类方法声明为

为什么没有产生重定义错误?

double & operator[](int i);double operator[](int i) const;

 


比如

class Student {....public:double & operator[](int i);double operator[](int i) const;...};student ada[3];ada[1] = ada[3];

 

会不会产生二义性?
不明白,,,,,,,,

 

经过网络提问,总结之后得出答案

double & operator[](int i);相当于friend double operator[](Student *this,int i);double operator[](int i) const;相当于friend double operator[](const Student * const thisint i);

 


不能忽略调用的隐式参数,自身!

 

0 0
原创粉丝点击