#include <iostream>
#include <boost/shared_ptr.hpp>
class test
{
public:
test(){std::cout << "test 被创建为空" << std::endl;}
test(const char* str):s(new std::string(str)){std::cout << "test 被创建" << std::endl;}
//~test(){std::cout << "test 被析构" << std::endl; std::cout << *s << std::endl;}
~test(){std::cout << "test 被析构" << std::endl; }
private:
boost::shared_ptr<std::string> s;
};
class mysql_cfg_t
{
private:
boost::shared_ptr<std::string> ip;
boost::shared_ptr<test> t;
public:
mysql_cfg_t(const char* ip):ip(new std::string(ip)),t(new test()){}
~mysql_cfg_t(){std::cout << "mysql_cfg_t 被析构" << std::endl;}
void set_test(const char* n){t.reset(new test(n));}
};
boost::shared_ptr<mysql_cfg_t> v()
{
boost::shared_ptr<mysql_cfg_t> mysql( new mysql_cfg_t("127.0.0.1"));
std::cout << "do nothing" << std::endl;
mysql->set_test("b");
return mysql;
}
int main()
{
std::cout << "<<>>" << std::endl;
boost::shared_ptr<mysql_cfg_t> mysql_cfg = v();
std::cout << "<<>>" << std::endl;
return 0;
}