C++11 操作员<&书信电报;在模板类中;具有名称空间;

C++11 操作员<&书信电报;在模板类中;具有名称空间;,c++11,linker,mingw,C++11,Linker,Mingw,我在链接下面的代码时遇到问题。链接器找不到朋友模板函数的实现。 你知道为什么它找不到它吗 声明 // XY.hpp namespace xxx { template<typename T> class XY; template<typename T> std::ostream& operator<<(std::ostream&, const XY<T>&); template<typename T> cla

我在链接下面的代码时遇到问题。链接器找不到朋友模板函数的实现。 你知道为什么它找不到它吗

声明

// XY.hpp
namespace xxx
{

template<typename T> class XY;

template<typename T>
std::ostream& operator<<(std::ostream&, const XY<T>&);

template<typename T>
class XY
{
public:
    // ... constructors, destructor, getters, setters, etc
    friend      std::ostream& operator<< <T>(std::ostream&, const XY<T>&);

private:
    //...

};

} /* namespace xxx*/
//XY.hpp
名称空间xxx
{
模板类XY;
模板
std::ostream&operator没有operator
// XY.cpp
#include "XY.hpp"

namespace xxx
{

template<typename T>
std::ostream& operator<<(std::ostream& os, const XY<T>& rhs)
{
    // ...
    return os;
}
} /* namespace xxx */
// main.cpp
#include "XY.hpp"
#include <iostream>

using namespace std;
using namespace xxx;

int main() {
    XY<uint16_t> xy;
    cout << xy;

    return 0;
}