inheritence problem

This is a discussion on inheritence problem within the C++ Programming forums, part of the General Programming Boards category; hi i have a problem with this example that i copy online and is not working can someone help me ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    inheritence problem

    hi i have a problem with this example that i copy online and is not working can someone help me
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<iostream>
    using namespace std;
    class person
    {
         
      public:
                
                int age;
               person(int age){ this -> age =age;}
      
    };
    
    class basketballplayer:public person 
    {
                 public:
                 int point;
                 int steal;
                basketballplayer(int point, int steal, int age):person(age)
                 {
                  this -> point = point;
                  this -> steal = steal;
                 
                 };
                 
         
    };
    
    main()
    {
          basketballplayer tony; //why  is this not working
          tony.age=11;
        
         getch(); 
    }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    You have declared tony as a bb player, but you have not instantiated tony.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    96
    what is instantiated tony

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    The basketballplayer constructor requires 3 arguments, but you have supplied none.
    I'd also suggest properly indenting the code, making the member variables private.
    And finally making main return int, or the code will not compile.

    Example:
    basketballplayer tony(100, 100, 10000);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

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