I came up with a contradiction between the rules for overloading the output operator and what my code allowed me to do when I tried to provoque the error.
The class declares the operator unfriendly:
The cpp file for the class goes on defining it:Code:class Opers { public: /* ... */ std::ostream& operator<<(std::ostream&, const Opers&); private: /*... */ };
No errors, no warnings and the test in main() outputs correctly. This shouldn't happen from what I've been learning. The operator, being declared a member of Oper, should have the implicit This as the first parameter...Code:#include "oper.h" std::ostream& operator<<(std::ostream &os, const Opers &obj) { os << obj.val() << " - " << obj.text(); return os; }
What am I missing?



LinkBack URL
About LinkBacks



