How to avoid errors while using CRTP?

In C++0x you have a simple solution. I don’t know whether it is implemented in MSVC10 however.

template <typename T>
struct base
{
private:
    ~base() {}
    friend T;
};

// Doesn't compile (base class destructor is private)
struct foo : base<bar> { ... };

Leave a Comment