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);
Related Posts:
- outputting ascii table in C++
- How to read a file line by line or a whole text file at once?
- lvalue required as left operand of assignment – Array
- ‘cout’ was not declared in this scope
- streambuf::xsgetn and state flags
- ‘cout’ was not declared in this scope
- Why would we call cin.clear() and cin.ignore() after reading input?
- Error while overloading operator (must be a nonstatic member function)
- Reading from text file until EOF repeats last line
- error: ‘ostream’ does not name a type
- error: overloaded ‘operator<<' must be a binary operator (has 3 parameters)
- cin.eof() functionality
- C++ operator+ and operator+= overloading
- The difference between cin.ignore and cin.sync
- How to print (using cout) a number in binary form?
- Xcode 11.1: iostream’ file not found
- What’s the difference between while(cin) and while(cin >> num)
- How to solve “Unresolved inclusion:
” in a C++ file in Eclipse CDT? - Why is “using namespace std;” considered bad practice?
- What is a lambda expression in C++11?
- How to convert string to char array in C++?
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- How do I print out the contents of a vector?
- ‘was not declared in this scope’ error
- Good input validation loop using cin – C++
- Is there a C++ decompiler?
- What is a dangling pointer?
- undefined reference to WinMain@16 (codeblocks)
- Why use ‘glad’ library for opengl initialization? [duplicate]
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- How to reverse an std::string? [duplicate]
- What is the C version of RMI
- Difference between ‘strcpy’ and ‘strcpy_s’?
- What is uintptr_t data type
- Why am I getting this redefinition of class error?
- error: redefinition of class
- How to convert a std::string to const char* or char*
- What is the difference between a static and const variable?
- What is move semantics?
- unsigned int vs. size_t
- error: expected primary-expression before ‘)’ token (C)
- What does -> mean in C++?
- Why doesn’t std::vector::push_front() exist?
- Fastest way to check if a file exist using standard C++/C++11,14,17/C?
- Invalid use of non-static member function c++
- C++ #include guards
- Is std::stoi actually safe to use?
- C++ forbids variable-size array
- Fill array with random numbers within a specified range (C++)
- Remove an array element and shift the remaining ones
- Right way to split an std::string into a vector
- string subscript out of range error
- push_back vs emplace_back
- No operator << matches these operands
- Returning an empty string : efficient way in c++
- How to find the size of an int[]?
- Append an int to a std::string
- Decimal to hex conversion c++ built-in function
- C++ IDE with repl?
- Already defined in .obj – no double inclusions
- expected unqualified-id before string constant
- C++: Access violation writing location
- error: strcpy was not declared in this scope
- how to print a string to console in c++
- How to call a parent class function from derived class function?
- Error: No instance of constructor matches the argument list
- How can I get the list of files in a directory using C or C++?
- RPN Calculator for C++
- What does `Fatal Python error: PyThreadState_Get: no current thread` mean?
- Debug Assertion Failed: _CrtIsValidHeapPointer(block)
- gdb error not in executable format: File format not recognized
- C++ Erase vector element by value rather than by position?
- C++ – include unistd.h: why not cunistd?
- Dynamically allocated string array, then change it’s value?
- Use the auto keyword in C++ STL
- c++ –
- C++ – statement cannot resolve address for overloaded function
- What’s the difference between * and & in C?
- is there is a compiler which convert c++ code into mips assembly language
- how to convert from int to char*?
- When is it safe to call this-> in constructor and destructor
- Stray ‘\342’ in C++ program
- gcc -g :what will happen
- QByteArray to QString
- Bitwise Less than or Equal to
- Unrecognizable template declaration/definition
- MSVCP120d.dll missing
- Modulo operator with negative values [duplicate]
- Finding the type of an object in C++
- C++ Simple Dice roll – how to return multiple different random numbers [duplicate]
- How can I get a file’s size in C++?
- Why can’t I make a vector of references?
- What does “-Wall” in “g++ -Wall test.cpp -o test” do?
- C++ equivalent of StringBuffer/StringBuilder?
- Struct with template variables in C++
- error: no member function declared in class
- Why does my program give “NULL used in arithmetic”
- no matching function to call for “getline”