[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Overload Resolution in C++

zbigniew

10/29/2008 11:46:00 AM

Can someone explain me how overload resolution works in C++?

For example if I have function void f(char, int); and I will call
f('A', 3.1) or f(1.5, 3.1F) what would be the result?

Thanks
2 Answers

Victor Bazarov

10/29/2008 1:06:00 PM

0

zbigniew@szymczyk.eu wrote:
> Can someone explain me how overload resolution works in C++?
>
> For example if I have function void f(char, int); and I will call
> f('A', 3.1) or f(1.5, 3.1F) what would be the result?

If you only have a single function called 'f', no overload is present.
Overload is only there if you have more than one function named 'f':

void f(char, int);
void f(long, double);

int main() {
f(0L, 0.0); // the latter is called
f('c', 42); // the former is called
}

Explaining how overload resolution "works" can take weeks. Please find
a decent C++ book and read the section/chapter on overloading.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

asterisc

10/29/2008 6:14:00 PM

0

On Oct 29, 3:06 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> zbign...@szymczyk.eu wrote:
> > Can someone explain me how overload resolution works in C++?
>
> > For example if I have function void f(char, int); and I will call
> > f('A', 3.1) or f(1.5, 3.1F) what would be the result?
>
> If you only have a single function called 'f', no overload is present.
> Overload is only there if you have more than one function named 'f':
>
>      void f(char, int);
>      void f(long, double);
>
>      int main() {
>          f(0L, 0.0); // the latter is called
>          f('c', 42); // the former is called
>      }
>
> Explaining how overload resolution "works" can take weeks.  Please find
> a decent C++ book and read the section/chapter on overloading.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask

Indeed. However, there are some rules that are followed, which are not
that complicated.
Try looking:
http://accu.org/index.php/jo...