template<class T>
class Test
{
public:
template<class Other>
class show
{
public:
typedef Test<Other> other;
};
};
template<typename T, class A = std::allocate<T> >
class SList
{
//....
struct Node
{
//....
};
//typedef A::show<Node>::other alloc; 出错
typedef typename A::template show<Node>::other alloc;
};
在采用typename 消除歧义中,我们有时必须告诉编译器,某个嵌套的名字是一个类型名字
(而不是一个非类型名字),这样编译器才能正确执行解析工作。对于嵌套的模板名字也同样存
这样的情况
本文探讨了C++中使用typename关键字来明确指定嵌套名称为类型的重要性,特别是当涉及到模板时。通过示例说明如何正确使用typename来避免编译错误。
628

被折叠的 条评论
为什么被折叠?



