I have a question. I was playing with enable_shared_from_this
and noticed a strange thing. This example works fine:
#include <iostream>
#include <memory>
using namespace std;
struct Test : enable_shared_from_this<Test>
{
};
int main() {
shared_ptr<Test> ptr(new Test);
return 0;
}
But when I change struct
to class
it stops compiling!
The error says:
/usr/include/c++/4.8/bits/shared_ptr_base.h:772:58: error: ‘std::enable_shared_from_this’ is an inaccessible base of ‘Test’ __enable_shared_from_this_helper(_M_refcount, __p, __p);
Does anyone have a clue why it is so?