相关疑难解决方法(0)

模板基类typedef和函数的更好的C++语法?

我有使用VC9(Microsoft Visual C++ 2008 SP1)编译的代码,但没有使用GCC 4.2(在Mac上,如果这很重要).如果我填写足够的限定符和关键字,我可以强制它在GCC中工作,但这似乎不对.

这是一个展示我的问题的最小代码示例:

template< typename N >
struct B {
    typedef N n_type;                     // can derived class access typedef?
    void foo() {}                         // can derived class access function?
};

template< typename N >
struct D : public B<N> {

    typedef B<N> b_type;
    typedef typename b_type::n_type bn_type;

    void f1( n_type ) {}                  // ERROR: 'n_type' has not been
                                          // declared

    void f2( typename B<N>::n_type ) {}   // OK, verbose

    void f3( b_type::n_type ) {}          // ERROR: 'struct …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates

8
推荐指数
1
解决办法
3014
查看次数

标签 统计

c++ ×1

gcc ×1

templates ×1