Question:
what is meaning of operator overloading and function overloading?
anonymous
2010-06-25 01:30:10 UTC
How function call is done in c++ when their 2 functions with same name?How they differentiate?
Four answers:
Bob M
2010-06-25 02:04:25 UTC
Operator overload allows you to define a mathematical operator to operate on types other than numeric.



For example you might have a string class and you want the '+' operator to concatenate strings, this allows you to write a line such as this -



string myString = "Hello" + "world



You can also use this with classes, you might have an iage class, or just an extension of the existing Image class, and want to add an overload so that you can add images into a gif animation



myImage = picture1 + picture2



Obviously you have to write the operator's function, but in your your code that uses this operator it is much easier to see what you are doing.



Function overloads -



private void Print(string printThis)

private void Print(int printThis)



Now you can use the print and the one of the type you are passing is used,



Print(20)

Print("Hello")



You no longer need a new function name for each variation of your own print function, but the type list can not be the same. You can not overload using -



private void Print(string printThis)

private void Print(string printSomethingElse)



Because the compiler needs the difference in types to mangle the names, name mangling is really just a way for the compiler to create individual names for each function that you have overloaded.
?
2016-12-07 00:38:09 UTC
Operator overloading in simple terms ability the comparable element as overloading the different element in C++. Overloading in C++ ability you're changing some thing with yet another function that are comparable yet does issues somewhat diverse. In different words operator overloading is fairly like function overloading in simple terms utilized to an operator. you are able to particularly write a function in C++ which will overload the ++ operator and fairly will do a subtraction operation. The compiler would be conscious of to apply your overloaded function fairly then the unique function frequently based on the variety of variable you bypass to the function or the variety it returns. i'd have put in some code samples yet yahoo would not incredibly like it as quickly as I do this.
anonymous
2010-06-25 01:55:09 UTC
Any operator such as + can be overloaded in C++. For example:



fullName = fName + lName;



+ is concactinating two strings.



Now:



sum = 1 + 5;



perofrming addition.



That is it!



Function overloadig means the same function NAME can be used to perform on Different Number of Arguments / Parameters and also Return Type.



For example:



void yahoo(int age);



void yahoo(char *name, int age);



Check out them with your own ideas!



Function call is handled first by compiler which does this smart work at compile time, then it is the responsibility of the OS to alocate memory for it, called Buffer. For run time function call resolution we need dyanamic polymorphism. Just use Virtual Functions!
Jhon
2010-06-25 01:31:22 UTC
dont get wat you meen


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...