test.cpp,最小测试代码
#include <memory>
class Parent{ // A Interface That I can't modify! can't add 'friend' or modify 'protected'
protected:
virtual ~Parent(){};
public:
// other interfaces that no one is suitable for 'delete this'
};
class Derived : public Parent{ // My class
public:
virtual ~Derived(){}
};
class Deleter : public Parent // My deleter to use unique_ptr
{
public:
void operator()(Parent* ptr)
{
delete ptr; // Actually Wrong? cannot access ptr's protected & private member
}
};
int main(int argc, …Run Code Online (Sandbox Code Playgroud)