const可以使得函数重载

来源:互联网 发布:apache编译调试选项 编辑:程序博客网 时间:2024/05/01 11:23

#include<iostream>using namespace std;class Test{public: Test(int i,int j):m(i),n(j) { }int Get(){    return m;} int Get() const{    return m+n;}private:    int m;    int n;};void main(){   Test t1(3,4);   const Test t2(3,4);   cout<<t1.Get()<<endl;   cout<<t2.Get()<<endl;}


上述输出为3,7;可见const可以让两个同名函数发生重载的。

0 0
原创粉丝点击