make_shared

boost学习之--shared_ptr

感情迁移 提交于 2019-12-27 21:35:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在boost中,有一个智能指针类shared_ptr可以管理好我们的指针 。这里我不详解,以下列出使用例子。自己现写现调通过的哈: #include <iostream> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> using namespace std; using namespace boost; class Person { public: Person(string name, int age) : m_name(name), m_age(age) { cout << "construct" << endl; } ~Person() { cout << "destruct" << endl; } void print(void) { cout << "name:" << m_name << ", age:" << m_age << endl; } private: string m_name; int m_age; }; int main( int argc, char *argv[] ) { cout << "Hello, This is a test of shared_prt" << endl; if (1) {