首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于类成员函数,该怎么解决

2012-03-18 
关于类成员函数C/C++ codeclass VAC{public:int f() const{return 3}int f(){return 5}//这不属于函数重

关于类成员函数

C/C++ code
class VAC{public:    int f() const    {        return 3;    }        int f()     {        return 5;    }      //这不属于函数重载 为什么不出错。 };


[解决办法]
const函数也是函数重载的一种方式。
[解决办法]
其实就是对类成员函数有一个隐藏的this指针这个事实不清楚才有这种疑惑的,假如我们不隐藏this,函数写出这样,你还有疑惑么?

C/C++ code
class VAC{public:    int f(const VAC * this)     {        return 3;    }        int f(VAS * this)     {        return 5;    }      }; 

热点排行