
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various topics in object oriented programming (oop), including const objects, static variables, and member initializer lists. Students will learn about the concept of constant objects, how to initialize data members using member initializer lists, and the order of initialization. The document also discusses the difference between class and instance variables, and how to define and initialize static data members.
Typology: Slides
1 / 32
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