class Book
{
public:
Book(string na, string au, int page, float price):
name(na),author(au),page(page),price(price)
{
cout<<"书名:"<<name<<endl
<<"作者:"<<author<<endl
<<"页数:"<<page<<endl
<<"价格:"<<price<<endl;
}
Book(string na, string au):
name(na),author(au)
{
cout<<"书名:"<<name<<endl
<<"作者:"<<author<<endl;
}
Book()
{
cout<<"新建Book对象"<<endl;
}
~Book()
{
cout<<"回收Book对象"<<endl;
}
string name;
string author;
int page;
float price;
};
int main()
{
Book b1("sa","zero",12,34);
Book b2("sa","zero");
Book b3;
return 0;
}
原文地址:http://blog.51cto.com/13615683/2096239