-1

类.h

template<class T>
  struct AStruct
  {
     //stuff
  };

class aClass
{
  template<class T>
  void setStruct(const AStruct<T>& s)
  {
    theStruct = s; 
  }

private:
  template<class T>
  AStruct<T> theStruct;  //this is not liked.  "multiple template parameter lists are not allowed" are one of the errors I get... 
}; 

相当混乱,但仍然,我想知道可以做些什么......我试过玩了一下,但没有运气......另外,请只使用标准库!

4

3 回答 3

4
template<class T>
struct AStruct{
};

template<class T>         //<-- the template must be here
class aClass {
public:
    void setStruct(const AStruct<T>& s){
         theStruct = s; 
    }
private:
    AStruct<T> theStruct; //<-- To construct this variable
};
于 2013-08-16T14:40:27.500 回答
2

去除template<class T>

template<class T>
struct AStruct{
 //stuff
};

template<class T>
class aClass{

 void setStruct(const AStruct<T>& s){
  theStruct = s; 
}

private:
AStruct<T> theStruct;   
}; 

您已经定义AStruct为模板

于 2013-08-16T14:15:26.857 回答
2

如果您持有的成员是类模板,那么您要么需要类模板,要么需要为模板参数提供类型。看来您需要前者:

template<class T>
class aClass
{
  void setStruct(const AStruct<T>& s){
   theStruct = s; 
  }

private:
  AStruct<T> theStruct; // data member is class template
}; 
于 2013-08-16T14:40:45.967 回答