Why do we need typename here?

前端 未结 4 1840
故里飘歌
故里飘歌 2020-11-27 06:02
template
class Set 
{
public:
   void insert(const T& item);
   void remove(const T& item);
private:
   std::list rep;
}

template<         


        
4条回答
  •  野性不改
    2020-11-27 06:52

    typename is needed in your declaration of 'it' because otherwise the compiler doesn't know that it's a type declaration rather than an expression.

    According to this page, "Use the keyword typename if you have a qualified name that refers to a type and depends on a template parameter."

提交回复
热议问题