Hi All,
I have doubt in my mind regarding declaration of cin and cout object . As per my understanding cin and cout both object are accessible in main then they shouldn't have protected.in below code snippet i have overloaded both input and output operator and
while giving new name (ofstream obj) to user defined version of this operator , I am getting error like obj is protected and can't be accessed here. Anybody can suggest .
#include<iostream>
using namespace std;
class overload
{
public:
int var_a;
overload (int fun_a=10): var_a(fun_a) {}
friend ostream operator >> (ostream &output, overload &);
friend istream operator << (istream &input, overload &);
};
overload operator +( int a , overload &p1 )
{ overload k;
return ( k.var_a= a+k.var_a);
}
ostream &operator <<( ostream &output, overload &s1)
{
output<<"value of object output:"<<s1.var_a<<endl;
return output;
}
istream &operator >>( istream &input, overload &s1)
{
input >> s1.var_a;
return input;
}
int main()
{
overload s1,s2;
//ostream obj;
//obj<<"enter the value of object"
cout<<"enter the value of object";
cin>>s2;
cout<<s2;
return 1;
}