Question

Consider this:

template < typename VectorType >
void ff()
{
    // This passes.
    typedef typename VectorType::value_type VV;
    typedef int VV::* MM;

    // This FAILS!??
    typedef int typename VectorType::value_type::* MMM;
}

Why the second fails and what is the correct way to get the desired typedef in one typedef statement?

My compiler is the GCC-4.7.2.

Was it helpful?

Solution

As pointed out in the comments, you have a typename where it shouldn't be:

typedef int typename VectorType::value_type::* MMM;

should be just:

typedef int VectorType::value_type::* MMM;

typename is used when you have a::b inside a template, a depends on template parameters and b is a type. In that case, you have to use typename a::b to communicate this fact to the compiler.

On the other hand, you're doing a::b::*, which is a clear indicator that b must be a type, so typename cannot be used here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top