December 2010
Intermediate to advanced
451 pages
11h 16m
English
You want to give a function the ability to accept multiple parameter types instead of being constrained to a particular datatype or number of parameters. For example, you want to create a single function that can accept either one or two parameters and that will perform a slightly different action depending upon the number of parameters you pass it.
Use overloading to create multiple functions that are named the same and perform similar functionality but accept a different number of parameters, different ordering of parameters, or parameters of different types. In this recipe, you will see a function named squared that takes a number and returns its value squared. Similarly, ...
Read now
Unlock full access