Computer Science 1037A/B Lecture 23: this Pointer and Constant Member Functions

13 views2 pages

Document Summary

By default, the compiler provides each member function of a class with an implicit parameter that points to the object through which the member function is called. A constant member function is one that does not modify the object through which it is called this pointer: Implicit parameter passed to a member function points to the object calling the function const member function: does not modify its calling object. Example(int a){ x = a;} void setvalue(int); void printaddressandvalue(); //set value of object void example::setvalue(int a) x = a; " << this << " has << "value. //print the addresses of the two object cout << "addresses of objects are " << &ob1 << "and" << &ob2. //print the addresses and values from within the member function. ob1. printaddressandvalue(); ob2. printaddressandvalue(); return 0; The object at address 0x241ff5c has value 10. The object at address 0x241ff58 has value 20.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions