Thread: Inheritnace problem

  1. #1
    Unregistered
    Guest

    Inheritnace problem

    this inheritance program is giving me problems about decleration on lines 17 and 20.

    ---------------------------------------------------------------------------------

    #include <iostream.h>
    #include <string.h>

    class Pair {
    public:
    Pair (int num1, int num2) {
    aNum1 = num1;
    aNum2 = num2;
    }
    Pair () {
    aNum1 = 0;
    aNum2 = 0;
    }
    void output () {
    cout << aNum1 << " " << aNum2 << endl;
    }
    setNum1 (int num) {
    aNum1 = num;
    }
    setNum2 (int num) {
    aNum2 = num;
    }
    private:
    int aNum1;
    int aNum2;
    };

    main () {

    Pair numPair (12, 34);
    numPair.output ();
    numPair.setNum2 (21);
    numPair.output ();

    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >setNum1 (int num) {
    and
    >setNum2 (int num) {
    Both of these method definitions are missing a return type, put void in front of them both and it should compile fine (with a warning about main not returning a value of course).

    -Prelude
    My best code is written with the delete key.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Also, if you define functions in your class definition, you also need a semicolon after the bracket signaling the end of the function definition.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >you also need a semicolon after the bracket signaling the end of the function
    It isn't required, but is sometimes considered good style. I personally don't see the need, but I rarely define functions inside my class definition anyway.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM