overload c++ example
Example 1: c++ function overload
/*A function over load in c++ is when you take a function with the same definition but change the input variables.
This can include multiple functions with the same name see below
*/
#include <iostream>
using namespace std;
int function1(int var1){//example of single variable
//do somthing
}
int function1(int var1,int var2){//of overload
//do somthing
}
int function1(int var1,string var3){//of overload
//do somthing
}
int main(){
cout << "Hello World" << endl;
function1(4);
function1(3,-90);
function1(34,"it works");//these should all work even tho they have different input variables
return 0;
}
Example 2: c++ operator overloading
// money.h -- define the prototype
class Money
{
public:
Money & operator += (const Money &rhs);
}
// money.cpp -- define the implementation
Money& Money :: operator += (const Money &rhs)
{
// Yadda Yadda
return *this;
}