-
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();
}
-
You have declared tony as a bb player, but you have not instantiated tony.
-
what is instantiated tony
-
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);