拷贝构造函数
#include <iostream>
using namespace std;
class book
{
public:
book(){}
book(book &b);
book(char* a, double p = 5.0);
void display();
private:
double price;
char * title;
};
book::book(book &b)
{
price = b.price;
title = b.title;
}
book::book(char* a, double p)
{
title = a;
price = p;
}
void book::display()
{
if(title == NULL)
{
cout<<"The title null " <<endl;
}
else
{
cout<<"The price of "<<title<<" is $"<<price<<endl;
}
}
int main()
{
cout << "Hello World!" << endl;
book b2("books");
b2.display();
book b3(b2);
b3.display();
return 0;
}
