具有模板类模板参数的模板类的变量设置为具有该变量的派生模板的基模板
Variable of a template class with a template class template parameter set to a base template of the derived template with the variable
我正在尝试创建一个派生类(普通模板),它有一个模板类型的变量,该变量的模板类参数为派生类(带变量的)的基类类型(普通模板,与派生类的参数相同)。这让VC++对我非常愤怒,我无法平息它的愤怒。这里有一个快速的例子:
template<template<typename VT> class CT, typename VT> struct encapThing {};
template<typename VT> struct innocuousBase {};
template<typename VT> struct derivOfDoom : public innocuousBase<VT>
{
encapThing<innocuousBase, VT> ohgodhelp; //C3200
};
它将抛出一个C3200,表示它需要一个类模板。现在,我明白了为什么这可能会认为模板中存在模板的递归循环,即使事实并非如此。否则,我如何说服VC++?
在derivOfDoom<>
内部不合格地使用innocuousBase
会被解释为innocuousBase<VT>
,就像在该上下文中不合格地用derivOfDoom
会被解释成derivOfDoom<VT>
一样。我不记得这是否是符合标准的行为,但解决方法很简单:完全限定innocuousBase
,这样编译器就知道你指的是innocuousBase
类模板,而不是innocuousBase<VT>
基类:
template<typename VT> struct derivOfDoom : innocuousBase<VT>
{
encapThing<::innocuousBase, VT> ohgodhelp;
};
相关文章:
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 继承时如何构建派生类的变量?
- 在派生类中使用基类的私有成员变量的最佳方法
- 如何使用 C++ 中的继承函数访问派生类中的局部变量
- 如何在C++中找到变量派生最多的子类?
- 从模板化父类中的派生内部类访问受保护的成员变量
- 使用语法公开派生类中的基类别名模板和变量模板?
- 如何将一个变量用于父类和派生类
- C++:使用基类中的仅派生类变量
- 如何根据基类对象中的变量值分配派生类中的变量?
- 如何从派生类访问引用成员变量?
- 为什么基指针可以访问虚拟函数中的派生成员变量
- "Rename"派生类中的成员变量
- OOP - 抽象类类型,初始化基类和派生类中的变量
- 从派生类 c++ 中获取变量
- 如何使黑客合法化,该黑客假定派生的类变量的相邻存储
- 如何从基类向量达到派生的类变量
- C++:使用变量派生.一小部分代码有问题