Thread: I don't know what this c++ method means!

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    16

    I don't know what this c++ method means!

    void Print(ostream&) const – this constant member function will display data of the objects through the ostream object in the argument.

    This is something I have to program.
    I guess I am suppose to take in an ostream object such as
    "cout"

    but i have no clue what to write
    Please help

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    16

    Unhappy

    nobody knows?

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    your not gonna get an answer right away... this isn't a chat... when somebody sees the question and knows the answer, they'll post it...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    16
    I think i figured it out

    I can take an object like

    obj.Print(cout).

    now my method can be


    cout<<(this.value);



    I think that's all there is to it?!?

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    This is kind of like overloading the >> ostream operator.
    Code:
    void ClassName::Print(&ostream os){
        os >> classvariable;
        os >> anotherprivatevariable;
    }
    .
    .
    Print should be public.
    .
    .
    ClassName.Print(cout);
    I think this is what you would do.

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    If that function is a member function of a class, then you should probably post something about the class, so that the rest of us know what that means.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    16
    curlious
    why did you use the >>operator?

    I read the api for cout and thought i had to use

    <<(const & primitive_type);

    ??

  8. #8
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    opps my bad you are correct it is the << operator but using
    cout << this.value will not work if value is private.
    classname.Print(cout); will work if you define the function like I said.

    Code:
    you can overload the << operator like this
    
    ostream & operator<<(ostream & os, const ClassName & object){
       os<< classvar;
       return os;
    }
    
    you should make the prototype a friend function in your class declaration
    
    then you can do this in main
    cout << classobject;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 10:43 AM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  4. Looking for criticism on my GameState class
    By Raigne in forum Game Programming
    Replies: 1
    Last Post: 03-21-2008, 09:45 AM
  5. Cubic Root by Newton's Iterative Method
    By amirahasanen1 in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2005, 02:05 PM