代码之家  ›  专栏  ›  技术社区  ›  Ben

模板类型参数的模板参数必须是类型;你忘了“typename”了吗?[重复]

  •  0
  • Ben  · 技术社区  · 5 年前

    在模板中,我必须将 typename template 依赖他人的名字?
    到底什么是从属名称?

    我有以下代码:

    template <typename T, typename Tail> // Tail will be a UnionNode too.
    struct UnionNode : public Tail {
        // ...
        template<typename U> struct inUnion {
            // Q: where to add typename/template here?
            typedef Tail::inUnion<U> dummy; 
        };
        template< > struct inUnion<T> {
        };
    };
    template <typename T> // For the last node Tn.
    struct UnionNode<T, void> {
        // ...
        template<typename U> struct inUnion {
            char fail[ -2 + (sizeof(U)%2) ]; // Cannot be instantiated for any U
        };
        template< > struct inUnion<T> {
        };
    };
    

    我的问题在于 typedef Tail::inUnion<U> dummy 线我很确定 inUnion 是一个独立的名称,VC++完全正确地扼杀了它。
    我也知道我应该能够补充 样板 告诉编译器inUnion是一个模板id的地方。但具体在哪里?然后它是否应该假设inUnion是一个类模板,即。 inUnion<U> 命名类型而不是函数?

    0 回复  |  直到 4 年前