【问题标题】:error: typedef name may not be a nested-name-specifier错误:typedef 名称可能不是嵌套名称说明符
【发布时间】:2010-06-13 07:36:15
【问题描述】:

我正在尝试按照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;
};

【问题讨论】:

    标签: c++ gcc boost


    【解决方案1】:

    typename T0 中删除typename

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

    并且可能还会删除第二个尖括号。即

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

    【讨论】:

    • 谢谢,真不敢相信我错过了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多