C++ has one more neat trick up it's sleeve for functions -- defining Default Parameters. What are they? Well, they're a way of saying what value should be passed to a function if you don't pass anything or have less arguments than are defined. Here's how you define a function to have default values in its argument list: void salsa(int yum=2)
Note that you're setting the parameter salsa();
Even though there was no argument passed, the function still works. Because
no value was passsed, the variable
salsa(231);
Would set void burrito(int taco, int nacho, int chimichanga=0, int beans=0) is good, but void burrito(int taco, int nacho=0, int chimichanga=0, int beans)
is bad, and won't work. Why not? Well imagine if you tried calling this
function with 3 arguments. Did you want to send values for |