Hızlı yanıt: kod örneği
stackoverflow.com overloading-operator-in-c
The correct way is listed everywhere overloading is discussed, and you've managed to miss pretty much all of it.The standard declaration is It cannot be a member function, and it needs to return a reference to the so that you can chain as normal.The definition, in your case, would be something likeNote that you return the incoming , and print what you like using the operator rather than using the operator. It's pretty simple if you follow this
form.In this case, the data members are public (which is not a good idea in general),
so there's no access problems. If you need to get inaccessible values (because
they're and not exposed in the public interface), you'll need to declare
the operator to be a in the class definition.
<<
ostream & operator<<(ostream & s, const & Line l);
ostream
<<
ostream & operator<<(ostream & s, const & Line l){ return s << "y = " << l.m << "x + " << l.b;}
ostream
<<
+
private
friend