-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprototype.cpp
56 lines (48 loc) · 910 Bytes
/
prototype.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
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
using namespace std;
class Goods;
typedef boost::shared_ptr<Goods> GOODS_PTR;
class Goods
{
public:
explicit Goods( const string& cat, const string& name )
:m_catergry( cat ), m_name( name )
{
}
GOODS_PTR clone( )
{
string name( "default" );
GOODS_PTR ptr( new Goods( m_catergry, name ) );
return ptr;
}
void setName( const string& name )
{
m_name = name;
}
void toString( )
{
cout<<"cat: "<<m_catergry<<" name: "<<m_name<<endl;
}
~Goods( )
{
cout<<"---------goods destroy"<<endl;
}
private:
string m_catergry;
string m_name;
};
int main( void )
{
string cat( "mobile" );
string name( "IPhone 6" );
Goods goods( cat, name );
goods.toString( );
string another( "samsung S6" );
GOODS_PTR ptr = goods.clone( );
ptr->toString( );
ptr->setName( another );
ptr->toString( );
return 0;
}