有点神奇,让我不理解了。
#include <iostream>#include <string>using namespace std;class Internet{public: Internet(string name,string address) { cout << "载入构造函数" << endl; Internet::name = name; Internet::address = address; } Internet(Internet &temp) { cout << "载入COPY 构造函数" << endl; Internet::name = temp.name; Internet::address = temp.address; } ~Internet() { cout << "载入析构函数!" << endl; }public: string name; string address;};void main(){ Internet a = Internet("中国软件开发实验室", "www.cndev-lab.com"); string q = a.name; cout << q << endl;}
#include <iostream>#include <string>using namespace std;class Internet{public: Internet(char *name,char *address) { cout << "载入构造函数" << endl; strcpy(Internet::name, name); strcpy(Internet::address, address); } Internet(Internet &temp) { cout << "载入COPY 构造函数" << endl; strcpy(Internet::name, temp.name); strcpy(Internet::address, temp.address); } ~Internet() { cout << "载入析构函数!" << endl; }public: char name[20]; char address[20];};void main(){ Internet a = Internet("中国软件开发实验室", "www.cndev-lab.com"); string q = a.name; cout << q << endl;}
public: string name; string address;
[解决办法]