|
One neat thing you can do in C++ is declare two different functions that have the same name. How can this be? By passing different variables, C++ can tell that you want to use one versus another. This might let you make a function that can handle both strings and numbers; just write separate functions with the same name for each type of variable. Sound neat? Well, let's try it out:
#include <iostream.h>
void burrito(int nacho)
{
cout << "You sent an int!" << endl;
}
void burrito(char foo)
{
cout << "You sent a char!" << endl;
}
void main(void)
{
burrito(42);
burrito('A');
burrito(452.2);
}
Neat, huh? The first time you call the function burrito((int)452.2);
Which would convert the number integer(52.1); Which would return 52. |