The problem is that you define it inside the class, which
a) means the second argument is implicit (this
) and
b) it will not do what you want it do, namely extend std::ostream
.
You have to define it as a free function:
class A { /* ... */ };
std::ostream& operator<<(std::ostream&, const A& a);
More Related Contents:
- How to properly overload the
- What are the basic rules and idioms for operator overloading?
- Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?
- Why does std::getline() skip input after a formatted extraction?
- Operator[][] overload
- C++ Standard Library: How to write wrappers for cout, cerr, cin and endl?
- Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?
- ‘printf’ vs. ‘cout’ in C++
- Overloading member access operators ->, .*
- What’s the right way to overload operator== for a class hierarchy?
- Difference between iostream and iostream.h
- How do I deal with the max macro in windows.h colliding with max in std?
- overloading new/delete
- Why should the assignment operator return a reference to the object?
- How to overload the operator++ in two different ways for postfix a++ and prefix ++a?
- Rationale of enforcing some operators to be members
- return value of operator overloading in C++
- How do the stream manipulators work?
- What the point of using std::ios_base::binary?
- How to overload unary minus operator in C++?
- Reading and writing to the same file using the same fstream
- How do we declare a friend function with a class template into .h file and define them into a .cpp file (not all in one header file)?
- What’s the difference between while(cin) and while(cin >> num)
- Operator overload which permits capturing with rvalue but not assigning to
- How can I use a custom type as key for a map in C++?
- Loading a file into a vector
- Why default three-way operator (spaceship ) generates equality operator (==) and user define three-way operator not?
- How can it be useful to overload the “function call” operator?
- How to overload operator==() for a pointer to the class?
- friend declaration declares a non-template function [duplicate]