vendredi 28 décembre 2018

Create a dynamic array of pointers and assign different subclass objects to them

I've been having trouble accessing the "getDegreeProgram()" method in my objects that are set to my array of pointers; all of my baseclass methods are working, but for some reason, my subclass methods aren't even visible. I'm new to c++ and stackoverflow, so if you need any additional code or information about my project, let me know. Thanks in advance.

roster.h:

   class roster { 
   private:   
   student** classRosterArray; //array of pointers

roster.cpp function that creates my objects and sets them to the array of pointers


   void roster::createStudentObject() {
      classRosterArray = new student *[5]; //array of pointers
   if (degreeProgramInput == "NETWORK") {
      classRosterArray[rosterCounter] = new networkStudent();
   }
   else if (degreeProgramInput == "SECURITY") {
      classRosterArray[rosterCounter] = new securityStudent();
   }
   else classRosterArray[rosterCounter] = new softwareStudent();  
   }

student.h subclasses in question (they're subclasses of my baseclass "student")

    class networkStudent:public student {
    private: 
      int networkDegree;
    public:
      int getDegreeProgram();
      networkStudent();
    };
    class securityStudent:public student {
    private:
      int securityDegree;
    public:
      int getDegreeProgram();
      securityStudent();
    };
    class softwareStudent:public student {
    private:
      int softwareDegree;
    public:
      int getDegreeProgram();
      softwareStudent();
    };    

Aucun commentaire:

Enregistrer un commentaire