How do the compiler choose the right overloadedfunction

Nov 7, 2012 at 9:48am
Helle there,

i got a question about the compiler.
If i have two function:
1) int foo (char a, int b);
2) int foo (int a, int b);

The compiler can differ the functions by the parameter. So far, so good.

But what is it about that two (member-)functions:
1) int& bar (int a);
2) const int& bar (int a) const;

How can it differ these functions?

Greetings
Last edited on Nov 7, 2012 at 10:01am
Nov 7, 2012 at 10:19am
It doesn't. The following won't compile:

1
2
3
4
5
int& bar (int a);
const int& bar (int a) const;
int main()
{
}


The compiler complains about non-member functions with const qualifiers and being unable to tell the two functions apart.
Nov 7, 2012 at 10:39am
And if it is a Memberfunktion?
I ask because i read the stl-vector reference ("at"-function)
Topic archived. No new replies allowed.