//
// const对象只能调用const this函数。
// 非const 对象可以调用const this函数和非const this函数
//
// void display() const : 编译器将该函数变形为: void display( const Type* this ) ;
// ( const Type* 指向的对象是不能改变的 )
//
// void display() : 编译器将该函数变形为: void display( Type* this ) ;
//
//
//
#include <iostream>
using namespace std ;
class Test
{
public:
Test() { }
void display() { cout << "dislapy()" << endl ; }
void display() const { cout << "display() const" << endl ; }
} ;
int main()
{
Test t1 ;
const Test t2 ;
t1.display() ;
t2.display() ;
return 0 ;
}
C++中的const数据成员和cons成员函数
最新推荐文章于 2023-06-07 15:01:08 发布