EECE 2560 Lecture : EECE3326_Jan8_2014 - Copying and Passing Objects

63 views3 pages

Document Summary

When functions are only one line or two, sometimes you don"t need to write a dedicated funciton for it. You can put the code directly into the class declaration. int time24::gethour() const t1. gethour() Countt::count(int val) void count::set(int val) set (val); x = val; int gethour const. Const (int); void pnt() { count << r << endl;} void set (int); int x; int main() Increment x(0,10); acounter. set(0); void clear(const acounter) %wrong way to implement. Will not permamently change value of counter1 when we call it in main (above) //when you pass an object by value, the object is copied. Changes aren"t visible outside the function > default memberwise copying happens. //we want to pass a value by reference. void clear (const &acounter) //&acounter is an alias for the object passed in. //when we pass by reference, changes to objects are visible outside the function no copy is made. Const member functions - don"t change any data members within other objects.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents