const成员函数

来源:互联网 发布:cf刷烈龙软件 编辑:程序博客网 时间:2024/06/10 18:30
#include <iostream>using namespace std;class A {int i;public:A() : i(0) {}void f() { cout << "f()" << endl; }void f() const { cout << "f() const" << endl; }};int int main(int argc, char const *argv[]){const A a;a.f();return 0;}

输出:f() const

分析:

   事实上:这两个函数为f(A *this)和f(const A *this)。

0 0
原创粉丝点击