#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX()const{return x;}
};
void main()
{
const C c(5);
cout<<c.getX();
system("pause");
}
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int x){this->x = x;}
int getX(){return x;}
};
void main()
{
C c(5);
cout<<c.getX();
system("pause");
}
出错原因是常变量成员只能用常对象来调用
我认为第一种好,运用了长对象成员的调用