<分区>
由于某些原因,下面的代码给出了错误Symbol 'TemplateBase' could not be resolved.
:
template <typename T>
class TemplateBase
{
TemplateBase(std::map<std::string, T>::const_iterator anIterator)
{ }
};
class SubClass : public TemplateBase<int>
{
SubClass(std::map<std::string, int>::const_iterator anIterator) :
TemplateBase<int>(anIterator) //Error: Symbol 'TemplateBase' could not be resolved.
{ }
};
奇怪的是,当我删除 ::const_iterator
时没有出现错误并且只有 std::map<std::string, int>
遗迹:
template <typename T>
class TemplateBase
{
TemplateBase(std::map<std::string, T> aMap)
{ }
};
class SubClass : public TemplateBase<int>
{
SubClass(std::map<std::string, int> aMap) :
TemplateBase<int>(aMap) //No error.
{ }
};
此外,下面的函数也没有报错,所以它看起来确实与模板基类调用与 const_iterator 的组合有关:
void function()
{
std::map<std::string, int>::const_iterator anIterator;
TemplateBase<int> aTemplateBase(anIterator); //No error
}
是否有一些我不知道的规则禁止使用 const_iterator 作为基类模板构造函数的参数?或者这是一个编译器错误?
我正在使用 C++11 在 Windows 7 上使用 MinGW 64 位 4.9.0 进行编译。