operator inside operator not working
char b;
operator<<(cout,(operator>>(cin,b)));
this is not compili开发者_如何学Cng in vc++ because all 8 overloads cant convert this type.
can any one explain this.....
is their a problem with return type...........
The stream extraction operation i.e. op>>
returns an object of type istream&
. The op<<
does not have an overload which takes istream&
as its second parameter. You need to split the two actions or define one such overload.
The problem is that the output operator that would work takes a void*
, but that is a member. If you change it to the following, it will convert the istream&
returned by the operator>>
to void*
and output it (and it is a null pointer if the extraction worked, and a non-NULL pointer otherwise):
cout.operator<<(operator>>(cin,b));
I'm not quite sure though why you are doing this. Can you please elaborate? If you want to output all stuff from cin
right away, use the underlying buffer
cout << cin.rdbuf();
char b;
operator<<(cout,(operator>>(cin,b),b));
精彩评论