64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <memory>
#include <vector>
using namespace std;
class Person
{
public:
Person(string name) : pName(new string(name)){}
~Person(){}
void printName() { cout << *pName << endl; }
private:
unique_ptr<string> pName;
//shared_ptr<string> pName;
};
int main()
{
vector<Person> persons;
Person p("George");
persons.push_back(p);
persons.front().printName();
cout << "==========\n";
return 0;
}