Question

let say i have a student class with a program class pointer for programEnrolled? how to i do the getter and setter and how do i access the member inside the programEnrolled (programName, programFees) through programEnrolled?

and when should i use a pointer function?

class clsStudent
{
private:
    string studentName;
    string studentID;
    clsProgram *programEnrolled;
};

class clsProgram{
private:
    string programName;
    double programFees;
    string programCode;
};
Was it helpful?

Solution

Why you need pointers in your program at all? By the way here is an example:

class clsStudent
{
public:
   void setProgram(clsProgram *x) { programEnrolled=x; }
   clsProgram *getProgram() const { return programEnrolled; }

  ...
};

clsStudent student;
student.getProgram()->programName;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top