
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Review
Student Class
class Student{ … int rollNo; public: Student(int aNo); int getRollNo(); void setRollNo(int aNo); … };
Modified Student Class
class Student{ … const int rollNo; public: Student(int aNo); int getRollNo(); void setRollNo(int aNo); … };
Example
void Student::SetRollNo(int i)
{
rollNo = i; /error: cannot modify a constant data member/
}
Member Initializer List
Order of Initialization
Example
Example
int main()
{
const Student aStudent; return 0;
}
Example
int main(){
const Student aStudent; int a = aStudent.getRollNo(); //error
}
const Objects
Example
int main(){
const Student aStudent; int a = aStudent.getRollNo();
}
Constant data members