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;
}
 
posted @ 2013-07-09 19:45  Predator  阅读(2251)  评论(0编辑  收藏  举报