I have a private variable in my Student
class defined as:
const int studentNumnber;
I am trying to write a copy constructor for the Student
and I need to cast away the constness to do this. Unfortunately, I don't understand how to use std::const_cast
.
This is what I am trying to do in my copy constructor:
Student(const Student & s)
: Person(p.getName(), p.getEmailAddress(), p.getBirthDate()), school(0), studentNumber(0) {
school = new char[strlen(s.school) + 1];
strcpy_s(school, strlen(s.school) + 1, s.school);
const_cast<int*>(this)->studentNumber = s.studentNumber;
//studentNumber = s.studentNumber);
}
That doesn't work... I am unsure of the syntax.