#include <string> #include <iostream> using namespace std; class A{ const string name; public: A(const string& id=""):name(id){} ~A(){} void print(){ cout << name<<endl; } }; class B{ string name; public: B(const string id){name=id;} ~B(){} void print(){ cout << name<<endl; } }; int main(){ A aa("aa"); aa.print(); B bb("bb"); bb.print(); }
转载于:https://www.cnblogs.com/york-hust/archive/2012/06/01/2530435.html