C++ Template: 'is not derived from type'

后端 未结 2 888
忘掉有多难
忘掉有多难 2021-01-18 06:04

Why is this code not valid?

#include 

template 
class A {
  public:
    A() { v.clear(); }

    std::vector *&         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 06:38

    In this line, you are missing the typename keyword:

    std::vector *>::const_iterator begin(){
    

    You need:

    typename std::vector *>::const_iterator begin(){
    

    This because std::vector *> is dependent on the template parameter (T) of the class template (A). To enable correct parsing of the template without having to make any assumptions about possible specializations of any other templates, the language rules require you to indicate which dependent names denote types by using the typename keyword.

提交回复
热议问题