You are overloading <<
operator as a member function, therefore, the first parameter is implicitly the calling object.
You should either overload it as friend
function or as a free function. For example:
overloading as friend
function.
friend ostream& operator<<(ostream& out, int x){ out << names[x] << " " << ages[x] <<endl; return out; }
However, the canonical way is to overload it as free
function. You can find very good information from this post: C++ operator overloading
Related Posts:
- Why do we need virtual functions in C++?
- How do I fix a “Expected Primary-expression before ‘)’ token” error?
- What are the rules of the std::cin object in C++?
- assignment operator overloading in c++
- C++ code file extension? What is the difference between .cc and .cpp
- C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive]
- lvalue required as left operand of assignment – Array
- segmentation fault 11 in C++ on Mac
- How to append text to a text file in C++?
- In C++, what is wx.h?
- Error while overloading operator (must be a nonstatic member function)
- Using “super” in C++
- new types may not be defined in a return type – C++
- error: ‘ostream’ does not name a type
- error: overloaded ‘operator<<' must be a binary operator (has 3 parameters)
- declaring a priority_queue in c++ with a custom comparator
- C++ undefined reference to WinMain@16 (Code::Blocks)
- bit vectors in c++
- Very basic inheritance: error: expected class-name before ‘{’ token
- mkdir c++ function
- C++ operator+ and operator+= overloading
- Error: “expected primary-expression before int”
- operator << must take exactly one argument
- How do I check if a Key is pressed on C++
- The Definitive C++ Book Guide and List
- rand() between 0 and 1
- how to implement Interfaces in C++?
- What is the proper declaration of main in C++?
- What exactly is nullptr?
- Different between ./ , ../ , ../../ , ~/ on file path(URL) in asp.net
- How to make a SIMPLE C++ Makefile
- Difference between associative entity and associative relationship attribute?
- max value of integer
- “items list” or “item list”
- When and why do I need to use cin.ignore() in C++?
- What does int & mean
- PHP – exit or return which is better?
- Evaluate a string with a switch in C++ [duplicate]
- How do you copy and paste into Git Bash
- What does LPCWSTR stand for and how should it be handled with?
- A warning – comparison between signed and unsigned integer expressions
- How to resolve ‘preflight is invalid (redirect)’ or ‘redirect is not allowed for a preflight request’
- Implement touch using Python?
- How can I convert const char* to string and then back to char*?
- How to override equals method in Java
- Socket API or library for C++?
- Initialize empty vector in structure – c++
- C++ catching all exceptions
- error: new types may not be defined in a return type
- c++: No instance of overloaded function?
- error: passing ‘const …’ as ‘this’ argument of ‘…’ discards qualifiers
- JMS Topic vs Queues
- RPN Calculator for C++
- How to set the authorization header using cURL
- How can I get the list of files in a directory using C or C++?
- How do you make a HTTP request with C++?
- Error: C2228: left of ” must have class/struct/union
- yum error “Cannot retrieve metalink for repository: epel. Please verify its path and try again” updating ContextBroker
- error C2679: binary ‘<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
- OCaml: Match expression inside another one?
- Which is faster C++ String length() or size()?
- creating an array of structs in c++
- How to read lines of text from file and put them into an array
- PostgreSQL: Query has no destination for result data
- server error:405 – HTTP verb used to access this page is not allowed
- Undefined reference to class constructor, including .cpp file fixes
- Subtract 1 day with PHP
- Why can’t we pass arrays to function by value?
- How to draw line in OpenGL?
- c++ sizeof( string )
- How can I add reflection to a C++ application?
- C++ floating point to integer type conversions
- How to get an average in C++?
- C++: variable ‘std::ifstream ifs’ has initializer but incomplete type
- template argument 1 is invalid (Code::Blocks Win Vista) – i don’t use templates
- error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
- Normalizing a list of numbers in Python
- Displaying contents of a vector container in C++
- Fastest way to extract frames using ffmpeg?
- Efficient Taxonomy Intersection
- Using stackexchange markup in WordPress (plugin?)
- Can't get on my own web page
- Home screen width Stretch [closed]
- What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?
- How to set environment variable in systemd service?
- Symlink not updating as expected when using an absolute with relative path
- How to include multiple domains in an spf TXT Record
- Physically locating the server
- Good tools that fit on a thumb drive [closed]
- How do you answer yes for yum install automatically
- All servers flooded by salt water, is it possible to recover data from multi-platter drives?
- How to check if I’m in screen session?
- How to zip/unzip files in Powershell?
- Cooling Server Closet – No A/C Is Possible
- Is it better practice to buy RAID disks individually vs. in bulk?
- What range of MAC addresses can I safely use for my virtual machines?
- What sysadmin things should every programmer know?
- Why do systems generally disable virtualization by default in BIOS settings?
- 10 servers to administer and I’m a history major [closed]
- Making `wget` not save the page