• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[C++] Constructors with polymorphism

N

nebulousmenace

Guest
#1
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;
}
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix