Suppose we had an istream subclass with the following method:
SomeStream& operator>>(Something& something) {
// .. write data into something
}
And we also had the following global method:
Something& operator>>(istream& stream, Something& something) {
// .. write data from stream into something
}
How does C++ know which method to call for the following code:
instanceOfSomeStream >> instanceOfSomething;
Follow up question: what is the better or more common way to allow a SomeStream to be written into a Something - should I add another overload for operator>> in SomeStream, that takes a Something& argument? Or should I go the opposite way, and create an overload in Something that takes a SomeStream? (Actually not in Something, but as a global function because of obvious reasons).