11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13: Making Classes Work 181This class definition contains nothing more than a prototype declaration forthe function deposit(). The function definition appears separately. Themember function prototype declaration in the structure is analogous to anyother prototype declaration and, like all prototype declarations, is required.Notice how the function nickname deposit() was good enough when thefunction was defined within the class. When defined outside the class, however,the function requires its extended name.Overloading Member FunctionsMember functions can be overloaded in the same way that conventional functionsare overloaded (see Chapter 6 if you don’t remember what that means).Remember, however, that the class name is part of the extended name. Thus,the following functions are all legal:class Student{public:// grade -- return the current grade point averagefloat grade();// grade -- set the grade and return previous valuefloat grade(float newGPA);// ...data members and other stuff...};class Slope{public:// grade -- return the percentage grade of the slopefloat grade();// ...stuff goes here too...};// grade -- return the letter equivalent of a numerical gradechar grade(float value);int main(int argcs, char* pArgs[]){Student s;s.grade(3.5); // Student::grade(float)float v = s.grade(); // Student::grade()char c = grade(v);// ::grade(float)}Slope o;float m = o.grade(); // Slope::grade()return 0;

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

Saved successfully!

Ooh no, something went wrong!