Why do we need typename here?

前端 未结 4 1832
故里飘歌
故里飘歌 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:54

    I think in general you need both the typename/class T in the class declaration as well as function definitions because you can define full/partial template specifications for function definitions. Ie. you could specialize your remove function for ints, strings, whatever it happens to be. So in this case you're telling the compiler "This is the general template, for any type" then later you might define the same function specified for only integers.

提交回复
热议问题