Hi!
I'm wondering how to override the operator<< because it doesn't seem to work for me. I'm trying to make it just output a string as a test but it just outputs some weird address(like 15x15ff4558 or something).
list is a pointer. And the stream output operator is printing the address of that pointer. If you want to print the object itself, you need to dereference the pointer.
This is not a correct definition of the operator. It takes two arguments, one being the left side (the stream) and the other being the right side (the object) like so:
I tried this, both with the 2 arguments aswell as taking a pointer and then use the -> to access its value but obviously it didn't work since I had the function inside the class and it kept telling me that the function needed exactly 1 argument.
How come it shouldn't be inside the class? :o I was taught that, for instance, the operator= should be inside the class..
Big thanks once again!
The assignment, array subscript, and function-call operators must appear inside a class definition.
The stream operators must appear outside a class definition[1].
Other operators may appear wherever you find it most convenient.
[1] Well, you can put stream operators inside the class definition by declaring them with the friend keyword, but this is essentially the same thing. The difference from other operators is that the first argument to the I/O operators must be an iostream, not the object.