我正在尝试拥有一个派生类(普通模板),它具有一个模板类型的变量,该变量具有作为其模板类参数的派生类的基类类型(普通模板,与派生类相同的参数)(带变量的那个).这让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
};
Run Code Online (Sandbox Code Playgroud)
它将抛出一个C3200,说它期望一个类模板.现在,我可以看到为什么这可能会认为模板中存在模板的递归循环,即使实际情况并非如此.我怎么能说服VC++呢?
不合格使用innocuousBase
inside ofderivOfDoom<>
被解释为innocuousBase<VT>
,就像derivOfDoom
在该上下文中不合格使用 of 被解释为 一样derivOfDoom<VT>
。我不记得这是否符合标准行为,但解决方法很简单:完全限定,innocuousBase
以便编译器知道您引用的是innocuousBase
类模板而不是innocuousBase<VT>
基类:
template<typename VT> struct derivOfDoom : innocuousBase<VT>
{
encapThing<::innocuousBase, VT> ohgodhelp;
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
181 次 |
最近记录: |