KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I haven't yet seen a pimpl example that utilizes both unique_ptr and move-semantics. I want to add a CHelper class to STL derived containers and use pimpl to hide what CHelper does. Does this look right? Derived.h class CDerived : public set<CSomeSharedPtr>, public CHelper { //... }; ` Helper.h // derived containers need to support both copy and move, so CHelper does too class CHelper { private: class impl; unique_ptr<impl> pimpl; public: //--- default: need both cotr & cotr (complete class) in order to use unique_ptr<impl> CHelper(); ~CHelper(); //--- copy CHelper(const CHelper &src); //copy constructor CHelper& operator=(const CHelper &src);//assignment operator //--- move CHelper(CHelper &&src); //move constructor CHelper& operator=(CHelper &&src);//move operator //--- expose public methods here void SetModified(BOOL bSet=TRUE); }; Helper.cpp //=========================== class CHelper::impl { public: BOOL m_bModified; //has the container been modified (needs to be saved) // ... other data impl() {m_bModified = FALSE;} //--- copy cotr/assign impl(const impl &src) { *this = src; } void operator=(const impl &src) { m_bModified = src.m_bModified; // ...other data } //--- move cotr/assign ?? do I need to write move cotr/assign ?? }; //============================ CHelper::CHelper() : pimpl(unique_ptr<impl>(new impl())) {} CHelper::~CHelper() {} //--- copy CHelper::CHelper(const CHelper &src) : pimpl(unique_ptr<impl>(new impl(*src.pimpl))) {} CHelper& CHelper::operator=(const CHelper &src) { if (this != &src) *pimpl = *src.pimpl; return *this; } //--- move CHelper::CHelper(CH
Tags (comma-separated)
Save Edits
Cancel