Consider the following code with overloaded insert and extract operators.
#include <iostream>
using namespace std;
class CTest
{
string d_name;
public:
friend ostream & operator<<(ostream & out, CTest & test);
friend istream & operator>>(istream & in, CTest & test);
};
ostream & operator<<(ostream & out, CTest & test)
{
out << "Name: " << test.d_name;
return out;
}
istream & operator>>(istream & in, CTest & test)
{
cout << "Enter your name: ";
string name;
if(in >> name)
test.d_name = name;
return in;
}
int main()
{
CTest test;
cin >> test;
cout << test;
}
Following this question, what is the meaning of the arguments ostream, out and istream and in? Since we can only see one argument (cin → test or cout <test), where in the caller are there ostream / istream links passed to (1) or (2)?
source
share