[C++] Constructors with polymorphism

N

nebulousmenace

Guest
I've got a base class with 2 ints and 3chars in the private section. My Derived classes have a few more ints and some calculated floats. I'm trying to pass the base class privates so that when a derived class is contructed, I can load in values for everything in the constructor. Is this even doable?

Here's the base:
PHP:
class athlete {
protected:	
char *firstname;
char *lastname;	
char *team;	
int jersey;	
int gplayed;

Ex. derived class:
PHP:
 class bball : public athlete{
private:
	int rebounds;
	int assists;
	int points;

and the main:
PHP:
void main()
{
	athlete *ptr;
	ptr = new bball("Steve", "Kerr", "Spurs", 25, 50, 5, 10, 5);
	ptr->calcFigs();
	ptr = new foot("Joe", "Blah", "LameGuys", 1, 12, 500, 500, 2);
	ptr->calcFigs();
	ptr = new base("Neil", "Garcia", "Marlins", 5, 10, 100, 20, 5, 1, 1);
	ptr->calcFigs();
	ptr = new judo("Morito", "Ushieba", "Tsunamis", 0, 30, 90, 15, 30);
	ptr->calcFigs();
	delete ptr;
}
 
It might help if you would paste the entire code so that we can take a look. i still dont understand what you are trying to do.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back