之前在Overloading operator <<中遇到过这个问题:无法将lvalue绑定到'std :: basic_ostream <char> &&',以下代码导致:
error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
Run Code Online (Sandbox Code Playgroud)
和代码:
// tried forward declaring but this did not help
namespace Tree {
template<typename> class Node;
};
template<typename T> std::ostream& operator<<(std::ostream&, const Tree::Node<T>&);
namespace Tree {
template<typename> class Tree;
template<typename T>
class Node {
friend inline std::ostream& operator<<(std::ostream& out, const Node& node) {
return out << node.getData();
}
friend class Tree<T>;
// member declarations
...
};
template<typename T> …Run Code Online (Sandbox Code Playgroud) c++ ×1