9.9 Functions and Overloading


9.9 Functions and Overloading

It is usually recommended that a function's name, return type, and argument list be unique so a compiler can distinguish one function from another, and so it will implicitly know which function a programmer intended to call. It is possible, however, for functions to have the same name and different argument lists; for example, SayHello(int variable) and SayHello(char variable). The process of creating multiple functions with the same name but different arguments is called overloading. Consider the following code:

      void sort(int *Numlist)      {         //sort numbers....      }      void sort(char *Letters)      {         //sort letters....      } 
Note 

Typically, programmers do not overload functions for the sake of it, but rather for a specific purpose. One good reason to overload a function is when several functions achieve a similar purpose but operate on different data types. For example, a sort function can be used to sort a variety of data, such as numbers, letters, words, and so on. For this reason, there are times when it makes sense to use the same name for several functions.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

Similar book on Amazon
Beginning C++ Through Game Programming
Beginning C++ Through Game Programming
Beginning Game Programming
Beginning Game Programming
The Ultimate Guide to Video Game Writing and Design
The Ultimate Guide to Video Game Writing and Design

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net