错误:typedef name可能不是嵌套名称说明符

时间:2010-06-13 07:36:15

标签: c++ gcc boost

我正试图按照this answer的方式做一些事情,并努力奋斗:

$ gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)

file.cpp:7: error: template argument 1 is invalid  
file.cpp:7: error: typedef name may not be a nested-name-specifier

文件的违规部分:

template <class R, class C, class T0=void, class T1=void, class T2=void>
struct MemberWrap;

template <class R, class C, class T0>
struct MemberWrap<R, C, T0>{
    typedef R (C::*member_t)(T0);
    typedef typename boost::add_reference<typename T0>::type> TC0; // <---- offending line

    MemberWrap(member_t f)
        : m_wrapped(f){
    }

    R operator()(C* p, TC0 p0){
        GILRelease guard;
        return (p->*(this->m_wrapped))(p0);
    }

    member_t m_wrapped;
};

1 个答案:

答案 0 :(得分:5)

typename中删除typename T0

typedef typename boost::add_reference<typename T0>::type> TC0;

也可能掉落第二个尖括号。即。

typedef typename boost::add_reference<T0>::type TC0;