静态对象和非静态对象
#include "stdafx.h"
class TDate1
{
public:
TDate1(int y,int m,int d);
TDate1()
{
cout<<"Default constructor called. \n";
}
~TDate1();
void Print();
private:
int year,month,day;
};
TDate1::TDate1(int y,int m,int d)
{
year = y;
month = m;
day = d;
cout<<"Constructor called.\t"<<d<<endl;
}
TDate1::~TDate1()
{
cout<<"Destructor called.\t"<<day<<endl;
}
void TDate1::Print()
{
cout<<year<<","<<month<<"."<<day<<endl;
}
int main(array<System::String ^> ^args)
{
//static TDate1 d1;
TDate1 d1;
TDate1 d2(2003,2,8);
cout<<"d1 is";
d1.Print();
cout<<"d2 is";
d2.Print();
int input;
cin>>input;
return 0;
}
问题是,这里定义静态对象的d1和非静态对象d1,为什么输出的值不一样?