OVERLOADING
Overloading is used for allowing multiple functions with the same name to have different behaviour.
The output does not matter in overloading.
Are the following overloads?
void lookup (Account);
void lookup (Account const);
void lookup(Account acc) {
//... Account acct;
lookup(acct);
}
void lookup(Account const acc) {
//... Account acct;
lookup(acct);
}
NO. The parameter is being passed in by pass by value. In both cases, a copy is being made. The compiler ignores the const.
int const ci=0; int i=10; int const *c=%ci; int *const tc=&i;
string s{"seattle"};
print(s);
print("singapore");
string const t{"seoul"};
print(t);
void printf(string) //works with "seattle", not with "singapore" void print(string const &) //works with "seattle", works with "singapore" void print(string &);
string s{"seattle"};
print(s);
void f(int); void f(double); char ch=10; f(ch); //which function call does it pick
Because chars are logically promoted to ints. However, this will never be tested because who the hell remembers these things.
Str::Str() : mLen(0), mPtr(new char [mLen+1]) { //This sets default members
*mPtr='\0';
}
Ambiguous calls causes a compile time error due to ambiguouity.
Perfect Fit, Promotion, Conversion (Promotion takes priority over Conversion)
Perfect Fit
Promotion char->int short->int
Conversion char->short
void fn(T1 a, T2 b) //random, a and b have equal priority, perfect fit, then promotion, then conversion)
IMPORTANT: RETURN TYPE DOES NOT MATTER
If downgrading is chosen, then warning
returning by value on an overloaded function is equal to calling the copy constructor.