所以我有我的模板类的一些问题。C++类嵌套到模板类
<!-- language: lang-c++ -->
template<class T>
class List {
class Counter
{
T real;
T imaginary;
Counter *next;
//....
public:
Counter(T a=0,T b=0);
virtual ~Counter();
friend ostream& operator<<(ostream&,Counter&);
friend ostream& operator<<(ostream&,List&);
};
Counter* first;
Counter* last;
//....
};
但我有一些方法的问题。如果我写的功能
template<class T> Counter operator/(Counter &one,...)
当我在VC++ 10看柜台它说,像
<error_type>&one
例如。我应该在代码中的任何地方使用template<class T>
作为我的Counter类吗?
//Methods
//Counter. For example some methods
Counter operator/(Counter& one,Counter& two){}
ostream& operator<<(ostream&os,Counter&x){}
istream& operator>>(istream&is,Counter&x){}
//List
template<class T>void List<T>::add(Counter *T,int i,bool c){}
是的,你应该。除非您定义函数内联,否则您需要为每个方法定义提供模板参数。 – atoMerz
据我所知,是的,如果你需要在计数器中使用模板类。 – swtdrgn