2011-10-23 49 views
1

为了澄清,我引述詹姆斯McNellis答案the post "Template assignment operator overloading mystery"赋值操作符的模板类

的隐式声明的拷贝赋值运算符,其声明如下,仍然产生:

Wrapper& operator=(const Wrapper&); 

现在我有一个类似的类,想知道这个运算符的定义需要什么样子。

这里的召回类:

template<typename T> 
struct Wrapper; 

- 现在是修正的比赛:

template<typename T> 
Wrapper& Wrapper<T>::operator=(const Wrapper&) 

Wrapper& Wrapper::operator=(const Wrapper&) 

或者这是一样的吗?

回答

2

template<typename T> 
Wrapper& Wrapper<T>::operator=(const Wrapper&) 

这实际上只是

template<typename T> 
Wrapper<T>& Wrapper<T>::operator=(const Wrapper<T>&) 

速记另一个版本将适用于一个名为Wrapper非模板类,但对你的模板没有影响。

+0

+1:太好了!非常感谢你! – Atmocreations