Lecture 6: Constants Flashcards
Initializer list is used for
const data members
Syntax of initializer list
Class::Class(int a, int b): A(a), B(b)
{}
Values are assigned in the initializer list in what order?
Order of declaration in class
When can the value of a const object be changed
Constructor and destructor
What is the main issue with const object?
Cannot access non const member function
Syntax for const member functions
int Date::get_month() const {} //both prototype and header
Both const and non const member functions can be called by
non const objects
3 functions that cannot be declared const
constructors
destructors
static member functions
Syntax of pointer to object
Date date, * dptr;
dptr = &date;
Syntax of const pointer to object
Date date; Date * const dptr = &date;
Syntax of pointer to const object
Date date;
const Date * dptr = &date;
Syntax of const pointer to const object
Date date; const Date * const dptr = &date;
In const member functions, this pointer is passed as
const pointer to const object