C++ C++;:朋友宣言‘;声明一个非模板函数

C++ C++;:朋友宣言‘;声明一个非模板函数,c++,templates,gcc,ostream,C++,Templates,Gcc,Ostream,我在重载时遇到了一个问题,您的代码中有两个不同的问题,第一个问题是friend声明(正如警告明确指出的,可能不太清楚)将单个非模板函数声明为friend。也就是说,当您实例化模板NVector时,它会声明一个非模板函数std::ostream&operator friend不是成员,并且运算符 template<class T, unsigned int TN> class NVector { inline friend std::ostream& operator&

我在重载
时遇到了一个问题,您的代码中有两个不同的问题,第一个问题是
friend
声明(正如警告明确指出的,可能不太清楚)将单个非模板函数声明为friend。也就是说,当您实例化模板
NVector
时,它会声明一个非模板函数
std::ostream&operator 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;
};
template <typename T, unsigned int TN>
class NVector {
   friend std::ostream& operator<<( std::ostream& o, NVector const & v ) {
      // code goes here
      return o;
   }
};
template<class T, unsigned int TN>
inline std::ostream& operator<<(std::ostream &lhs, const NVector<T, TN> &rhs)
{
    /* SOMETHING */
    return lhs;
};