我有一個問題重載<<
流運算符,我沒有找到解決辦法:C++:friend聲明「聲明一個非模板函數
template<class T, unsigned int TN>
class NVector
{
inline friend std::ostream& operator<< (
std::ostream &lhs, const NVector<T, TN> &rhs);
};
template<class T, unsigned int TN>
inline std::ostream& NVector<T, TN>::operator<<(
std::ostream &lhs, const NVector<T, TN> &rhs)
{
/* SOMETHING */
return lhs;
};
它產生以下錯誤消息:
warning : friend declaration ‘std::ostream& operator<<(std::ostream&, const NVector&)’ declares a non-template function [-Wnon-template-friend]
error: ‘std::ostream& NVector::operator<<(std::ostream&, const NVector&)’ must take exactly one argument
如何解決這個問題?
非常感謝。
一位朋友不是會員,'operator <<'不應該是會員。刪除定義標題中的分辨率。 – chris