#include <iostream>
using namespace std;
class A{
public:
void f(){cout << "f()" << endl;}
void f() const{cout << "f() const" << endl;}
};
int main(){
const A a;
a.f();
return 0;
}
输出结果: f() const
对于class A中的两个f()函数,实际上相当于:
void f(A* this){cout << "f()" << endl;}
void f(const A* this) const{cout << "f() const" << endl;}两个f()函数同样构成了Overload.
C++类成员函数重载与作用
1458

被折叠的 条评论
为什么被折叠?



