-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_sharedptr2.cpp
58 lines (48 loc) · 1.01 KB
/
std_sharedptr2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* =====================================================================================
*
* Filename: shareptr.cpp
*
* Description:
*
* Version: 1.0
* Created: 2015年04月06日 22时13分45秒
* Revision: none
* Compiler: gcc
*
* Author: zt (),
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <memory>
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<A> GetObj ( std::string a )
{
return std::make_shared<A> ( a );
}
std::string m_str;
};
int main ( int argc, char* argv[] )
{
( void ) argc;
( void ) argv;
std::shared_ptr<A> a = A::GetObj ( "fuck" );
a = A::GetObj ( "cao" );
//while ( 1 );
return 0;
}