Lecture 5: this Pointer Flashcards
1
Q
What is the difference between the memory allocation of the data members of an object of a class and its functions?
A
- When a new object is created, each object has specific memory reserved for its data members
- Functions of a class get memory that is shared by all objects of that class
2
Q
How does the function know which object of the class it has to act on?
A
• The address of the calling object is passed as a hidden argument to the function
The address is stored in the variable called this pointer
3
Q
Which has more precedence: dot operator or indirection operator?
A
Dot operator
4
Q
2 cases in which this pointer may be required explicitly
A
When local variable and data member have same name
To return reference to calling object