/* * ===================================================================================== * * Filename: shareptr.cpp * * Description: * * Version: 1.0 * Created: 2015年04月06日 22时13分45秒 * Revision: none * Compiler: gcc * * Author: zt (), * Organization: * * ===================================================================================== */ #include #include #include #include class A { public: A ( std::string a ) : m_str ( a ) { fprintf ( stderr, "A construct %s\n", m_str.c_str() ); } ~A() { fprintf ( stderr, "A destruct %s\n", m_str.c_str() ); } static std::shared_ptr GetObj ( std::string a ) { return std::make_shared ( a ); } std::string m_str; }; int main ( int argc, char* argv[] ) { ( void ) argc; ( void ) argv; std::shared_ptr a = A::GetObj ( "fuck" ); a = A::GetObj ( "cao" ); //while ( 1 ); return 0; }