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.

88 Part II: Becoming a Functional C++ Programmervoid someFunction(void){// ....perform some function}void someFunction(int n){// ...perform some different function}void someFunction(double d){// ...perform some very different function}void someFunction(int n1, int n2){// ....do something different yet}C++ still knows that the functions someFunction(void), someFunction(int),someFunction(double), and someFunction(int, int) are not the same.Like so many things that deal with computers, this has an analogy in thehuman world.void as an argument type is optional. sumFunction(void) andsumFunction() are the same function. A function has a shorthand name,such as someFunction(), in same way that I have the shorthand nameStephen (actually, my nickname is Randy, but work with me on this one).If there aren’t any other Stephens around, people can talk about Stephenbehind his back. If, however, there are other Stephens, no matter how handsomethey might be, people have to use their full names — in my case,Stephen Davis. As long as we use the entire name, no one gets confused —however many Stephens might be milling around. Similarly, the full name forone of the someFunctions() is someFunction(int). As long as this fullname is unique, no confusion occurs.The analogies between the computer world (wherever that is) and the humanworld are hardly surprising because humans build computers. (I wonder . . .if dogs had built computers, would the standard unit of memory be a gnawinstead of a byte? Would requests group in packs instead of queues?)Here’s a typical application that uses overloaded functions with unique fullnames:int intVariable1, intVariable2; // equivalent to// int Variable1;// int Variable2;double doubleVariable;// functions are distinguished by the type of// the argument passed

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

Saved successfully!

Ooh no, something went wrong!