Thread: inheritence problem

  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
    Chappell Hill, Texas
    Posts
    2,332
    You have declared tony as a bb player, but you have not instantiated tony.
    Mainframe assembler programmer by trade. C coder when I can.

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

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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, 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