C++成员函数返回智能指针

// xmlTest.cpp : 定义控制台应用程序的入口点。
//
 
#include "stdafx.h"
#include "FGConfig.h"
#include "Utils.h"
#include "persistable.h"
#include <iostream>
#include <string>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
using namespace boost;
 
using namespace std;
using namespace xml_api;
 
class Person
{
public:
	Person(){}
	Person(string name):m_strName(name){}
	void ShowMsg(){cout << m_strName << endl;}
	~Person(){cout << "deconstruction" << endl;}
private:
	string m_strName;
};
 
class Test
{
public:	 
	Test(){}
	~Test(){}
public:
	boost::shared_ptr<Person>  GetPerson();
};
 
boost::shared_ptr<Person>  Test::GetPerson()
{
	boost::shared_ptr<Person> person = boost::make_shared<Person>("ganquanfu");
	return person;
 
}
 
int _tmain(int argc, _TCHAR* argv[])
{
	
 
 
	Test test;
	boost::shared_ptr<Person> myPerson = test.GetPerson();
	cout << myPerson.use_count() << endl;
	myPerson->ShowMsg();
	int wait;
	cin >> wait;
 
	return 0;
}
 

原文链接: https://www.cnblogs.com/ganquanfu2008/p/3180794.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++成员函数返回智能指针

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/95112

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 上午2:57
下一篇 2023年2月10日 上午2:57

相关推荐