#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->x = x;}
int getX(){return x;}
};
void main()
{
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()const
{return x;}
};
void main()
{
C c(5);
cout<<c.getX();
system("pause");
}