[英]C++: Compile Error for Template Assignment Operator Overloading
當我在VC ++ 6中編譯以下代碼時,我不斷收到錯誤“使用類模板需要模板參數列表”。 這有什么問題?
template <class T>
class StdVector{
public:
StdVector & operator=(const StdVector &v);
};
template <typename T>
StdVector & StdVector<T>::operator=(const StdVector &v){
return *this;
}
您需要將模板參數放在返回類型中:
template <typename T>
StdVector<T> & StdVector<T>::operator=(const StdVector &v)
{
return *this;
}
它應該是
template <typename T>
StdVector<T> & StdVector<T>::operator=(const StdVector<T> &v)
{
return *this;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.