Help Bool Accepts int* as well until a bool function is overridden why is it so ?

I have a code as below..

1 #include <iostream>
2 #include <stdio.h>
3
4 void balaji(void *x, bool y)
5 {
6 printf("Balaji in BOOL %d \n", y);
7 }
8
9 main()
10 {
11 int i=0;
12 balaji(&i, &i);
13 }
14

ir prints true and works, when I override balaji() with a new function balaji(void *, void *) this function is called instead of above bool function. Why is it allowing this ?, if I put as int instead of bool in above function compilation error happens...
> when I override overload balaji() with a new function balaji(void *, void *)
> this function is called instead of above bool function. Why?

With int i = 0 ; evaluate balaji(&i, &i);

1. Candidate functions: void balaji( void*, bool ) and void balaji( void*, void* )

2. Viable functions: void balaji( void*, bool ) and void balaji( void*, void* )

3. Determine best viable function (rank the implicit conversions):

void balaji( void*, bool )
- argument 1: pointer-to-int => pointer-to-void
- argument 2: pointer-to-int => bool

void balaji( void*, void* )
- argument 1: pointer-to-int => pointer-to-void
- argument 2: pointer-to-int => pointer-to-void

For argument 1, the conversions are the same.
For argument 2, the conversion pointer-to-int => pointer-to-void is better than pointer-to-int => bool

Ergo, the overload resolves to void balaji( void*, void* ) (the best viable function)

For details, see: http://en.cppreference.com/w/cpp/language/overload_resolution


> I put as int instead of bool in above function compilation error happens...

There is no viable function: there is no implicit conversion sequence from pointer-to-int => int
Registered users can post here. Sign in or register to post.