一个函数重载问题

今天下午在看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);

 


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

 

posted @ 2013-11-14 13:09  残雪孤侠  阅读(115)  评论(0编辑  收藏  举报