Hi, I've one problem. I want to disallow to call destructor on object which I want always have in QSharedPointer. I was trying something as this:
class X
{
protected:
~X() {};
class Deleter;
friend class Deleter;
class Deleter
{
void operator()(X* p) { delete p; }
};
public:
QSharedPointer<X> create()
{
QSharedPointer<X> px = QSharedPointer<X>(new X(), X::Deleter());
return px;
}
};
class X
{
protected:
~X() {};
class Deleter;
friend class Deleter;
class Deleter
{
void operator()(X* p) { delete p; }
};
public:
QSharedPointer<X> create()
{
QSharedPointer<X> px = QSharedPointer<X>(new X(), X::Deleter());
return px;
}
};
To copy to clipboard, switch view to plain text mode
But this code is not compilable:
Error 1 error C2248: 'X::~X' : cannot access protected member declared in class 'X' c:\qt\4.6.2\src\corelib\tools\qsharedpointer_impl. h 391
It's probably because what QSharedPointer is implemented. But is there any way how to disallow to anybody to destrouy object using standard c++ pointer? I thing it will be much more secure and clearer.
Thanks.
Bookmarks