i am learning C++ 11 and with the following code i got this error message:
test.cpp:11:13: error: ‘static void Base::operator delete(void*)’ is protected
inline void Base::operator delete(void* p){
^
test.cpp:32:45: error: within this context
std::unique_ptr<Derived, Deleter> p(new Derived);
Question: why i got this error? how should i solve it? I thought that the protected member should also be accessible by the member function in derived class. Or am i using the unique_ptr wrongly?
test.cpp is as following:
#include <memory>
class Base{
public:
virtual void Release() const = 0;
protected:
virtual ~Base() = default;
static void operator delete(void* p);
};
inline void Base::operator delete(void* p){
::operator delete(p);
};
struct Deleter{
constexpr Deleter() noexcept = default;
void operator()(const Base* ptr) const{
ptr->Release();
}
};
class Derived : public Base{
public:
void Release() const;
};
void Derived::Release() const{
delete this;
}
int main(){
std::unique_ptr<Derived, Deleter> p(new Derived);
return 0;
}