Thread: Spot the problem..a test question, pls help!

  1. #1
    Unregistered
    Guest

    Spot the problem..a test question, pls help!

    Hi, this is a test qtion.
    What 3 problems exist in the following code? Can anyone help with a small explanation. I really don't get it. Thank you !!!!!!

    class problem
    {
    public:
    //c’tor
    problem();
    problem(int magnitude = BIG);

    //d’tor
    ~problem();

    //process functions
    bool get_out(bool lying, char *story);
    bool get_out(char *story, bool pass_the_buck = true);
    bool get_out(char *story = NULL, bool deny = true);
    bool fess_up(char *story=NULL, bool full_responsibility = false,
    bool is_me = true);
    bool bad(char *story, bool truth = true);
    bool bad(bool truth = false, char *story);
    };

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    A)This is probably your homework considering you did not register or sign in.

    B)You cannot set values or create them in the parameters for a function.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    B)You cannot set values or create them in the parameters for a function.
    Yes you can.They are called default values. Look it up Golfinguy.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    bool get_out(char *story, bool pass_the_buck = true);
    bool get_out(char *story = NULL, bool deny = true);


    hmmmm

    bool get_out (char*, bool)

    bool get_out(char*, bool)

    hmmmm
    Blue

  5. #5
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    problem(int magnitude = BIG);

    hmmm... where was BIG defined.
    Blue

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    bool bad(bool truth = false, char *story);

    is the last mistake because default parameters have to be on the right
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    You're so smart. Must be the wacky tabacky.
    Blue

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    My bad. Sorry about that. BTW, why would one want to do that if they could just declare them inside the function?

  9. #9
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    if you did it in the header, then the default values could be modified by the class user while the code in the implementation object file is still hidden.
    Blue

  10. #10
    For GolfinGuy,

    you can set default values for a function so you don't have to set every param/arg for the function when calling it. You only have to set the values of the params that are not set.

    bool get_out(char *story, bool pass_the_buck = true);

    //Call this
    get_out(p_myStory) //Don't need to set the other param since it's already set
    {return b_YorN;}
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  11. #11
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    a) Do your homework yourself.

    b) in addition to the ones above:

    problem();
    problem(int magnitude = BIG);

    Spot the problem ?
    If I leave out the parameters, which constructor will be called ?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File saving problem in DevC++ pls help ???
    By intruder in forum C Programming
    Replies: 3
    Last Post: 12-17-2002, 01:17 AM
  2. Question on an array practice problem
    By Vanished in forum C Programming
    Replies: 1
    Last Post: 01-22-2002, 07:12 PM
  3. STL Problem & Question
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 12-04-2001, 07:19 PM
  4. Pls Help Me In This Question!!!
    By Joanna in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2001, 02:05 PM
  5. A problem with my linked lists test.
    By valar_king in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:03 PM