简体   繁体   中英

Pointer to member of a typename

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM