Your constructor for Student is incomplete. It needs to set the regNo data member as well. Compare mine: Student(const string &name, int regNo) : name( name ), regNo( regNo ) {}
You pass regNo correctly, but you don't use it.
Note that, since you are inheriting regNo from another class, you may have to use the constructor for that. Whatever you do ... regNo needs to be set for each Student object.
Your constructor for Student is incomplete. It needs to set the regNo data member as well. Compare mine:
Student(const string &name, int regNo) : name( name ), regNo( regNo ) {}
i initialised the name using :
1 2
this->name = name;
;
added regNo to the initialisation list
but im getting error :
"student::regNo is private within this context" same for st.name
@Blendero, please refer to my code. Specifically, the writeStudents() routine. It is now using the "getters" for these private variables: for ( Student &st : studentlists ) cout << st.getRegNo() << " " << st.getName() << '\n';
and not direct access to the private variables regNo and name themselves.
I have defined these getters within my class definition:
You appear to have the first of them already; you will need to create the second (unless, in your implementation, it is already inherited from Person).
I stress: if they are private data members then you will have to write "getters" in a class definition to get their values.
@lastchance thank you very much you're a lifesaver xd, it is now working as required with the correct regno output, its been a long one i will now mark this as solved.