ok i know what this does...it allows to functions of the same name have different data,but why would i use this? why not just create a different function name
Printable View
ok i know what this does...it allows to functions of the same name have different data,but why would i use this? why not just create a different function name
Function overloading can be very handy. If you were creating say a game, you could use two functions with the same name but with different arguements say for two enemys. But you could still call both functions Enemy().
Also, in operator overloading, you can make the standard C++ operators do differnet things, example, you could make the '+' operator subtract for example. But messing with logical operators is somthing I am always keen to stay away from. If an operator was built to do a certaun thing, why change it?
I'm sure you use function overloading all the time, without even thinking about it:
Code:std::string str;
int i;
double d;
char c;
my_special_class myc;
std::cout << str << i << d << c << myc << "\n";
//here operator << is overloaded for various types to print a variable
well then,i suppose it definetly couldnt hurt to learn it.to say the least..and also,why did bs decide to let you change the operators?that seems odd what would be the point of making + equal -
That's abuse of operator overloading. :) It can be very useful when used properly, however. I'm sure you've used the + operator for strings to concatenate strings together, and =, <, and > to compare them.