Let's say I have the following piece of code (a simple CRTP class hierarchy). I want to typedef the base class type to save myself typing (in my actual code, I use the base class type more than once and the base class takes several template parameters), and I need to befriend the base class since I want to keep the implementation private.
template< class D >
class Base
{
public:
void foo() { *static_cast< D * >(this)->foo_i(); }
};
template< class T >
class Derived : public Base< Derived< T > >
{
public:
typedef class Base< Derived< T > > BaseType;
private:
// This here is the offending line
friend class BaseType;
void foo_i() { std::cout << "foo\n"; }
};
Derived< int > crash_dummy;
clang says:
[...]/main.cpp:38:22: error: elaborated type refers to a typedef
friend class BaseType;
^
[...]/main.cpp:33:44: note: declared here
typedef class Base< Derived< T > > BaseType;
How do I fix this? I noticed that I could simply type out the whole thing just for the friend class declaration and it works fine, but even a tiny bit of duplicated code makes me feel a tad uncomfortable, so I'm looking for a more elegant "proper" solution.