[求助]构造函数的输出~
#include<iostream.h>
class Myclass
{
public:
Myclass();
Myclass(int);
~Myclass();
void display();
protected:
int number;
};
Myclass::Myclass()
{
cout<<"constructing normally\n";
}
Myclass::Myclass(int m)
{
number=m;
cout<<"constructing a number"<<number<<endl;
}
void Myclass::display()
{
cout<<"display a number"<<number<<endl;
}
Myclass::~Myclass()
{
cout<<"destructing \n";
}
void main()
{
Myclass obj1;
Myclass obj2(20);
obj1.display();//输出的是随机数?
obj2.display();
}
红色部分是因为number是局部变量,未初始化,所以存放在内存中的是随机数?????