+-
typename应该在C之前或之后?
我应该写:

template<class T> class Foo {
    typename const T* x;
};

要么:

template<class T> class Foo {
    const typename T* x;
};
最佳答案
typename不是这样使用的,因此两种情况都是无效的,应该产生编译错误,如下所示:

main.cpp:4:20: error: expected a qualified name after 'typename'
    const typename T* x;
                   ^

在这里你需要像T :: myType这样的东西继续下去.

或者甚至是这,更糟糕的是:

main.cpp:4:14: error: expected a qualified name after 'typename'
    typename const T* x;
             ^
main.cpp:4:14: error: expected member name or ';' after declaration specifiers

expected a qualified name after ‘typename’中的相关示例.

The keyword typename was introduced to specify that the identifier that follows is a type

阅读更多:Officially, what is typename for?

点击查看更多相关文章

转载注明原文:typename应该在C之前或之后? - 乐贴网