以下代码在MVCC下编译但不是g ++,我不知道为什么.
template <typename T>
class A
{
public:
template <typename C>
class B
{
public:
C* cptr;
};
typedef typename A<T>::B<T> Ttype;
};
int main(int argc,char** argv)
{
A<int>::Ttype d;
d.cptr = 0;
}
Run Code Online (Sandbox Code Playgroud)
用g ++,你得到
error: 'typename A<T>::B name template<class T> template<class C> class A<T>::B', which is not a type
Run Code Online (Sandbox Code Playgroud)
我正在使用-std = c ++ 11进行编译
我认为这是MVCC的一个错误.这不会编译,因为您需要使用template歧义B作为模板:
typedef typename A<T>::template B<T> Ttype;
Run Code Online (Sandbox Code Playgroud)
根据gcc错误消息,问题是你声称A<T>::B是一种类型,但它不是:它是一个类模板.无论GCC和铛很满意
typedef A<T>::B<T> Ttype;
Run Code Online (Sandbox Code Playgroud)
即,删除typename.在给定的上下文中,不可能专注B于与显然无论如何不同的东西.
该using-alias不只是用不同的语法相同:
using Ttype = A<T>::B<T>;
Run Code Online (Sandbox Code Playgroud)
使用额外template关键字的符号首先表明B实际上是a template然后,与typename实例化B<T>是一个类型相结合:
typedef typename A<T>::template B<T> Ttype;
Run Code Online (Sandbox Code Playgroud)
要么
using Ttype = typename A<T>::template B<T>;
Run Code Online (Sandbox Code Playgroud)
由于课程模板B无论如何都是本地的,因此在这种情况下并不需要资格,即
typedef B<T> Ttype;
Run Code Online (Sandbox Code Playgroud)
和
using Ttype = B<T>;
Run Code Online (Sandbox Code Playgroud)
也工作.
| 归档时间: |
|
| 查看次数: |
304 次 |
| 最近记录: |