小编Joe*_*oey的帖子

重载operator <<(模板化)时如何修复"模糊过载"错误?

我试图重载<<运算符,但我得到以下错误:

错误:'std :: cout <<"Test"'中'operator <<'的模糊重载

..跟随50亿其他类似的错误:

c:\ mingw\bin ../ lib/gcc/mingw32/4.5.2/include/c ++/ostream:165:7:注意:候选人是:...

这是因为我在main.cpp文件中使用cout.

这是我的代码:

在BinTree.h中:

    template <typename T>
    class BinTree{
    ...
    friend std::ostream& operator<< <>(std::ostream&, const T&);
Run Code Online (Sandbox Code Playgroud)

在BinTree.cpp中:

    template <typename T>
    std::ostream& operator<< (std:: ostream& o, const T& value){
        return o << value;
    }
Run Code Online (Sandbox Code Playgroud)

在此先感谢您提供任何帮助.

c++ templates overloading compiler-errors operator-keyword

3
推荐指数
1
解决办法
1万
查看次数