小编And*_*w A的帖子

g ++不编译某些嵌套模板

当定义BREAK时,g ++ 4.7.2将不编译以下内容,我认为这是有效的C++.如果将A<U> tmp其更改为其他内容,它会使用BREAK进行编译,例如A<int> tmp- 虽然这使得最小测试用例在这里工作,但在我的实际应用程序中并不好.这里有什么不合法的C++吗?

template <typename T>
class B {

};

template <typename T>
class A {
public:
    template <typename U> B<U> *alloc_B( );
};

template <typename T> template <typename U>
B<U> *A<T>::alloc_B( ) {
    return new B<U>( );
}

#ifdef BREAK
template <typename T>
class C {
public:
    template <typename U> void x(B<U> &b) {
        A<U> tmp;
        B<U> *tmp2;
        tmp2 = tmp.alloc_B<U>( );
        delete tmp2;
    }
};
#endif

int main( ) {
    A<int> …
Run Code Online (Sandbox Code Playgroud)

c++ templates nested

3
推荐指数
2
解决办法
115
查看次数

标签 统计

c++ ×1

nested ×1

templates ×1