题目
Create a class without any constructors, and show that you can create objects with the default constructor. Now create a nondefault constructor (one with an argument) for the class, and try compiling again. Explain what happened.
代码
#include<iostream>
using namespace std;
class A
{
public:
A(int X=0){x=X+1;}
void show(){cout << x<<endl;}
private:
int x;
};
int main()
{
A test(5);
cout<< "x = " ;
test.show();
cout << endl;
return 0;
}