#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
class Person{
public:
Person(string name="Dennis",int age =34 ){
cout << " 默认构造函数";
}
Person(char* name):name(string(name)),age(34){
cout << " 转换构造函数1";
}
Person(double salary){
cout << " 转换构造函数2";
}
Person(string name, int age,double salary):name(name),age(age){
cout << " 一般构造函数1";
}
Person(string name,double salary):name(name){
cout << " 一般构造函数2";
}
Person(const Person& p):name(p.name),age(p.age){
cout << " 复制构造函数";
}
Person(Person&& p):name(p.name),age(p.age){
p.name = "" ;
p.age = 0;
cout << " 移动构造函数";
}
~Person(){
cout << " 析构函数";
}
private:
string name;
int age;
} ;
int main(){
cout << endl << "p1 :";
Person p1;
cout << endl << "p2 :";
Person p2 = "Super";
cout << endl << "p3 :";
Person p3 = 50000;
cout << endl << "p4 :";
Person p4("Super",34,20000);
cout << endl << "p5 :";
Person p5("Dennis",30000.00);
cout << endl << "p6 :";
Person p6(p3);
cout << endl << "p7 :";
Person p7 = Person();
cout << endl;
}