简单的构造函数,不明白
#include<iostream.h>
#include<string.h>
class B
{
public:
B()
{
cout<<"Default Constructor\n";
}
B(char *s,double n)
{
strcpy(name,s);
b=n;
cout<<"Constructor\n";
}
~B()
{
cout<<"Destructor"<<" " <<name<<endl;
}
void getb(char*s,double&n)
{
strcpy(s,name);
n=b;
}
private:
char name[80];
double b;
};
////////////////////////////////////////////////////
void main()
{
B*p;
double n;
char s[80];
p=new B[3];
p[0]=B("ma",4.8);//这里为虾米还会去调用的析构函数啊,是不是有一个临时对象啊?
p[1]=B("wang",3.6);
p[2]=B("li",3.1);
cout << "##############" << endl;
for(int i=0;i<3;i++)
{
p[i].getb(s,n);
cout<<s<<","<<n<<endl;
}
delete[] p;
}