Overload (programming): Difference between revisions

Content deleted Content added
spelling, wikified, +cat Overloading Methods, +add Overloading Operators, +add Overloading Constructors, -stub
m Minor edits to last
Line 32:
 
A [[compiler]] would be able to differentiate the two addition operators because one is passed three parameters instead of the normal addition which is passed just one. As mentioned above however, methods are overloaded based on their number AND type of parameters.
Another overloaded addition operator could be overloaded with three parameters IF the data types passed are different too. The compiler would differentiate those two by their data types. The following shows how it would be setup using an [[angle]] as a data type with [[Degree_(angle)|Degree]]-[[minute of arc|Minute]]-[[arcsecond|Second]] notation within the same program.
 
Angle Angle::Operator+(double Degree, double Minutes, double Seconds)
Line 38:
''code''
}
 
The different data types, one being integers, the other being doubles, allows this to be valid in the compiler. Any number of combinations could be created, as long as they don't have the same number of parameters of the same data types.
 
==Overloading Constructors==
Line 55 ⟶ 56:
cafe.total = 4.00;
 
By overloading the constructor, you could pass parameters into it to set the tip or total to a given value at creation. This shows the overloaded constructor with two parameters:
 
Bill(double setTip, double setTotal)