![]() |
can't overload << as member function
any idea why I can't overload << as member function
i.e Code:
template<typename T>I can overload the +, - inside and outside the class. But << and most probably >> has to be implemented as esternal function , why so ? any idea :) |
Re: can't overload << as member function
sorry for the typo . it should read in both operator lines:
"ostream& operator<<(ostream& os, Simple<T> P )" |
Re: can't overload << as member function
Because they are not the internal members of the class. the format in which you specify is such that the function needs to be external.
cout<<YourVariable<<endl; Now if you get into the operator overloading this should be OutputClassFunction.Operator <<(YourVariable) And so you need the first parameter as IO class variable and so you cannot have the function as internal. |
| All times are GMT +5.5. The time now is 17:16. |