11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

188Part III: Introduction to ClassesCalling a function with an object valueAs you know, C++ passes arguments to functions by reference when the argumenttype is flagged with the squiggly ‘&’ property (see Chapter 8). However,by default, C++ passes arguments to functions by value (you can checkChapter 6, on this one, if you insist).Complex, user-defined class objects are passed the same as simple intvalues as shown in the following PassObjVal program:// PassObjVal - attempts to change the value of an object// in a function fail when the object is// passed by value#include #include #include using namespace std;class Student{public:int semesterHours;float gpa;};void someFn(Student copyS){copyS.semesterHours = 10;copyS.gpa = 3.0;cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!