My program is telling me my Book class doesn't have an operator<< function even though it does. I'm trying to call it from my BST program. I did #include the Book.h file in both my BST.h and BST.cpp files.
Book doesn't have a operator<<.
You have a global function, called operator<< that receives an ostream and a Book, and that has access to the privates of the Book.
Which I think that you are calling correctly in line 6.
The error probably point you to lines 5 and 7, where I suspect you are trying to make a recursive call.
Sorry, here's the typing of the entire struct in BST.h:
1 2 3 4 5 6 7 8 9 10 11 12
class BST
{
private:
struct Node
{
Node *left;
Node *right;
Book bookNode;
};
Node *root;
Node *current;
@ne555 Yeah, the errors are on lines 5 and 7 and I'm trying to call it recursively. I just don't know how to call what I need using the operator<< in Book.h.
That obviously fails, for Book has no member operator<< of any kind.
Besides, operators are usually called with the other syntax: os << rhs.root->left << rhs.root->bookNode << rhs.root->right;
Make a standard standalone recursive function that takes ( std::ostream&, Node* ) and then call it from the operator<<( std::ostream&, BST& ).
Speaking of that operator:
* When does the loop end? The condition on line 3 should not change within the loop.
* Line 7 is never executed due to the return on line 6.
PS. Don't you ever have const Books or BST's to print? Surely the "print" operation does not modify the printed object?
It won't let me make the function that takes ( std::ostream&, Node* ) because it says that Node is undefined in my header file since I have to declare operators outside the standard class, even if I make it a friend.