12.14
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;
string destination = "目的";
string connection = "连接";
string Connect(string *) //获得一个连接
{
cout << "获得一个连接" << endl;
string temp = "连接1";
return temp;
}
void disconnect(string test)//关闭一个连接
{
test.clear();
cout << "关闭连接" << endl;
}
void end_connect(string *p)//结束一个连接
{
disconnect(*p);
}
void f(string &d)
{
string c = Connect(&d);
cout << c << endl;
shared_ptr<string>p(&c, end_connect);
}
int main()
{
f(connection);//即,首先connection进入Connect,c被置为“连接1”
//退出f之后c被销毁,而connection也被end_connect给清空
system("pause");
return 0;
}
12.15
更新中...............