mercredi 3 août 2016

Visibility problems when using CRTP

Here's a minimal example I could come up with:

template <typename T>
struct Util
{
    using Type = int;
};

struct A
{
    struct B : public Util<B> {
        void fun(Type) {}
    };
};

template <typename T>
struct C
{
    struct D : public Util<D> {
        void fun(Type) {}
    };
};

int main()
{
    A::B{}.fun(0);
    C<int>::D{}.fun(0);
}

The only difference between A::B and C::D is that C is a template.

Struct C::D fails to compile with the following error:

test_cpp.cpp:18:18: error: ‘Type’ has not been declared
         void fun(Type) {}
                  ^~~~

Why does this fails to compile? How do I make this compile?

Assume that Util is from external library and I cannot change it (it's boost::iterator_facade if you're courious).

Aucun commentaire:

Enregistrer un commentaire