overloading operator<<

From: Mark P (not_at_my.real.email)
Date: 10/29/04


Date: Fri, 29 Oct 2004 13:28:05 -0700

If I want to be able to write:

cout << SomeClassObject;

then the model I've seen requires a declaration in the SomeClass defition:

friend ostream& operator<< (ostream& out, const SomeClass& obj);

Is there any other way to do this with operator<< defined as a member
function of SomeClass so that it would only require one argument?
Something like:

ostream& operator<< (ostream& out);

where of course the "this" parameter would take the place of "obj" in
the first declaration I displayed.



Relevant Pages

  • Re: overloading operator<<
    ... |> cout << SomeClassObject; ... | needs to become a friend, which is all that your declaration serves. ... |> function of SomeClass so that it would only require one argument? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: main class and static
    ... Then I tried to remove static from the maindeclaration, and from most declaration in the source, but then the program refused to run, arguing "no main class can't be found", although compiling with no error. ... How to use waitin a static method? ... public class SomeClass { ... public void testMethod() { ...
    (comp.lang.java.help)
  • Re: overloading operator<<
    ... Now, in case this function needs to touch private parts of the class, it ... which is all that your declaration serves. ... > function of SomeClass so that it would only require one argument? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: overloading operator<<
    ... >>then the model I've seen requires a declaration in the SomeClass ... It requires a global function with this signature: ... > needs to become a friend, which is all that your declaration serves. ... SomeClass *pObj; ...
    (alt.comp.lang.learn.c-cpp)