MyClass *pObj = new MyClass();
customPtr
MyClass *customPtr = pObj;
delete customPtr;
C++ (Qt)template <class T> struct MyPtr { MyPtr( T * data = 0 ) : mData(data) {} T * data( void ) { return mData; } T * operator -> ( void ) { return data(); } private: T * mData;};
Можно попробовать сделать класс-обёртку с приватным оператором delete
C++ (Qt)class MyClass{public: MyClass(){ i = 5; } int getI() const{ return i; }private: int i;}; class Wrapper{public: Wrapper(MyClass *myClass) :myClass_(myClass){} int getI() const{ return myClass_->getI(); } private: MyClass *myClass_;};
C++ (Qt)void doSomething(Wrapper obj);MyClass *pObj = new MyClass();doSomething(pObj);
C++ (Qt)#include <memory> struct A{ int i;}; void modify(const std::unique_ptr<A> &ptr){ ptr->i = 3;} int main() { std::unique_ptr<A> pObj(new A); modify(pObj); return 0;}
C++ (Qt)class Custom : public Obj {...private: virtual ~Custom( void ) {}};
C++ (Qt)Сustom * customPtr;...Obj * obj = customPtr;delete obj;
C++ (Qt) class MyClass {/**/}; class MyClassCustomPtr {public: MyClassCustomPtr(MyClass*); private: MyClass* m_customPtr; }