#include #include #include #include #include #include using namespace std; class SecSet { public: typedef shared_ptr Ptr; private: vector _buf; // char * _buf=nullptr; size_t _len=0; public: SecSet(/* args */){}; ~SecSet(){ // if(_buf) delete _buf; _len=0; } void setBuf(const char * buf, size_t len){ // _buf.clear(); _buf.assign(buf,buf+len); // if(!_buf){ // _buf=new char[len] ;_len=len; // } // if (len>_len) // { // _buf=(char*)realloc(_buf,len) ;_len=len; // } // memcpy(_buf,buf,len); } void printBuf(){ printf("%s len %lu\n",_buf.data(),_buf.size()); } Ptr clone(){ return make_shared::type>(*this); } }; int main(){ const char hl[]={"Hello World!"}; const char hl2[]={"Hello World_twic!"}; SecSet::Ptr A=make_shared() ; A->setBuf(hl,sizeof(hl)); A->printBuf(); auto B=A->clone(); A->setBuf(hl2,sizeof(hl2)); A->printBuf(); B->printBuf(); A->setBuf(hl,sizeof(hl));A->printBuf(); B->printBuf(); return 0; }