Inheritnace problem

This is a discussion on Inheritnace problem within the C++ Programming forums, part of the General Programming Boards category; this inheritance program is giving me problems about decleration on lines 17 and 20. --------------------------------------------------------------------------------- #include <iostream.h> #include <string.h> class ...

  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,796
    >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,136
    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,796
    >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, 05: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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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