Why can't I call the constructor of the base class of the template using const_iterator?

For some reason, the following code gives an error 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.
    { }
};

Strange, when deleting ::const_iterator, an error does not appear, and only remains 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.
    { }
};

In addition, the following function also gives no errors, so it really seems to be related to the combination of calling the base class of the template using const_iterator:

void function()
{
    std::map<std::string, int>::const_iterator anIterator;
    TemplateBase<int> aTemplateBase(anIterator); //No error
}

Is there any rule against using const_iterator as an argument for base class template constructors that I don't know about? Or is this a compiler error?

I am compiling with MinGW 64bit 4.9.0 on Windows 7 using C ++ 11.

+4
1

, , typename:

TemplateBase(typename std::map<std::string, T>::const_iterator anIterator)
{ }
+6

Source: https://habr.com/ru/post/1542715/


All Articles