If You're Any Good At C++, You Should Know How To Fix My Problem.

This is a discussion on If You're Any Good At C++, You Should Know How To Fix My Problem. within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> class cat { public: int setAge(); int getAge(); private: int Age; }; cat::setAge(int): { } cat::getAge(); { return ...

  1. #1
    Registered User DeanDemon's Avatar
    Join Date
    Nov 2002
    Posts
    37

    If You're Any Good At C++, You Should Know How To Fix My Problem.

    #include <iostream.h>
    class cat
    {
    public:
    int setAge();
    int getAge();
    private:
    int Age;
    };
    cat::setAge(int):
    {
    }
    cat::getAge();
    {
    return Age;
    }
    main()
    {
    setAge(5);
    cout << getAge();
    return 0;
    }


    What's wrong with this code?
    -Dean

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: If You're Any Good At C++, You Should Know How To Fix My Problem.

    Originally posted by DeanDemon
    #include <iostream.h>
    class cat
    {
    public:
    int setAge(); // needs to be setAge(int x); need that variable
    int getAge();
    private:
    int Age;
    };
    cat::setAge(int x)//no semicolon, or colon here, notice variable here
    {
    Age = x;
    }
    cat::getAge()//no semicolon here
    {
    return Age;
    }
    main()
    {
    setAge(5);
    cout << getAge();
    return 0;
    }


    What's wrong with this code?
    that should work.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>What's wrong with this code?
    It's not in code tags
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    There are a few other problems with this code:

    1. setAge() is decalared as returning a value, however it doesn't.

    2. You need to instantiate the class in order to access its member functions.

    i.e.
    Code:
    int main(void)
    {
      cat Foo;
      Foo.setAge(5);
      cout << Foo.getAge();
      return 0;
    }
    3. getAge() is declared without a type, as you are returning an int it should be declared as such.
    Code:
    int getAge(void);
    
    // and later:
    
    int cat::getAge(void)
    {
       return Age;
    }
    Last edited by foniks munkee; 12-06-2002 at 01:41 AM.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    If You're Any Good At C++, You Should Know How To Fix My Problem.
    Then I should know how to fix your problem, but that title's what I call "manipulation". If I were these people here, I would have flamed you instead of helped you; you're very lucky that I wasn't the first person to reply.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    wow, I didn't even think about the other possible errors. oops...

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    87
    I'd have thought that main has to be intiated. Unless this is just what people get taught?
    **********************
    *==================*
    * Many Can. One Must... *
    *==================*
    **********************

  8. #8
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    If you are talking about having main return an int, yes - I typoed.. main should return an int. Otherwise I am not sure what you mean.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Originally posted by Hunter2
    Then I should know how to fix your problem, but that title's what I call "manipulation". If I were these people here, I would have flamed you instead of helped you; you're very lucky that I wasn't the first person to reply.
    Well I guess I'm too late for that too.

  10. #10
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> If You're Any Good At C++, You Should Know How To Fix My Problem.

    OOoooo...that sounds like a challenge.

    [note to self]This post would have been much funnier if it was at the beginning of the thread...[/note]

  11. #11
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    If You're Any Good At C++, You Should Know How To Fix My Problem.
    Are you saying you're not good at C++ and this is a desperate cry for help, or that you're such a newbie that you need to pressure people in here, even when you have no room to talk?
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  12. #12
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    >What's wrong with this code?

    it has errors in it. ask nice, and people might even help you fix them

  13. #13
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    >What's wrong with this code?

    Basic: You should be able to fix basic errors yourself.
    Advanced: You are using a totally outdated header file.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  14. #14
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Now guys i ad mit when i first saw this topic i thought "WTF?", but is it not possible that we have interpretted it the wrong way? Maybe he/she meant to say it like;

    "wow my question is really basic, so anyone with some experience should be able to help me narrow down the problem i can't find."

    But instead we took it wrong and got on his case? All i am saying is maybe he didn't mean it to come across as it did and we shouldn't ridicule him(yet).

  15. #15
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    true.. but s/he should have been more specific. isn't it against the rules to just post some code and say "what's wrong with this?", anyway? i think i read that somewhere...
    any compile errors (which i'm sure there were some) should have been listed, and a more specific question should have been asked.. not to mention s/he should have checked the FAQ/used the search button/put forth some effort to figure it out first. but i guess we'll put that aside
    just my two cents...

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. computer problem... me can't fix... internet
    By compjinx in forum Tech Board
    Replies: 2
    Last Post: 03-07-2003, 01:01 PM
  4. FAQ: Examples of good questions (General)
    By Prelude in forum FAQ Board
    Replies: 1
    Last Post: 10-11-2002, 08:57 PM
  5. What can I do?
    By Unregistered in forum C++ Programming
    Replies: 27
    Last Post: 07-16-2002, 11:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21