[C++] Constructors with polymorphism

Discussion in 'Web Design & Coding' started by nebulousmenace, May 21, 2003.

  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"25505105);
        
    ptr->calcFigs();
        
    ptr = new foot("Joe""Blah""LameGuys"1125005002);
        
    ptr->calcFigs();
        
    ptr = new base("Neil""Garcia""Marlins"51010020511);
        
    ptr->calcFigs();
        
    ptr = new judo("Morito""Ushieba""Tsunamis"030901530);
        
    ptr->calcFigs();
        
    delete ptr;
    }
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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.