【发布时间】:2011-10-16 05:36:14
【问题描述】:
我正在尝试重载
错误:'std::cout
..紧随其后的还有 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&);
在 BinTree.cpp 中:
template <typename T>
std::ostream& operator<< (std:: ostream& o, const T& value){
return o << value;
}
提前感谢您提供的任何帮助。
【问题讨论】:
-
我不完全相信你已经为我们提供了足够的代码来解决这个问题,但是你拥有给我们的信息让我问:为什么@ 987654323@ 是否需要访问
BinTree<T>的内部,如果它从不使用它们(或BinTree<T>)?
标签: c++ templates compiler-errors overloading operator-keyword