std::map::const_iterator template compilation error

前端 未结 3 1122
灰色年华
灰色年华 2020-12-20 00:56

I have a template class that contains a std::map that stores pointers to T which refuses to compile:

template 
class Foo
{
public         


        
3条回答
  •  轮回少年
    2020-12-20 01:57

    Use typename:

    typename std::map::const_iterator begin() const ...
    

    When this is first passed by the compiler, it doesn't know what T is. Thus, it also doesn't know wether const_iterator is actually a type or not.

    Such dependent names (dependent on a template parameter) are assumed to

    • not be types unless prefixed by typename
    • not to be templates unless directly prefixed by template.

提交回复
热议问题