修改一
#include <iostream>
using namespace std;
class C
{
private:
int x;
public:
C(int a);
int getX()const{return x;}
};
C::C(int a):x(a){}
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->xx = x;}
int getX(){return x;}
};
void main()
{
C c(5);
cout<<c.getX();
system("pause");
}
倾向于第二种吧,刚开始还不怎么熟悉这种博文发布形式,多试几次就会熟练使用这种发博文了