#include<iostream>
#include<stdlib.h>
using namespace std;
class C
{
private:
int x;
public:
C( int x){this->x = x;}
int getX()const{return x;}//定义常函数
};
int main()
{
const C c(5);//定义常对象
cout<<c.getX();//由常函数访问常对象
return 0;
}
常对象只能由常指针访问
最新推荐文章于 2020-05-27 14:27:47 发布