Monday, 11 July 2016

Priority of implicit conversion of user defined type and system defined type

No comments:
Guess the output?

class ArrayNotFound
       bool learnSomethingNew;
       ArrayNotFound(const char *p_char_pointer)
             std::cout<<"ArrayNotFound constructor"<<std::endl;   

void PostInArrayNotFound(const void *)
std::cout<<"void pointer parameter"<<std::endl;

void PostInArrayNotFound(ArrayNotFound p_obj)
std::cout<<"ArrayNotFound class parameter"<<std::endl;     

int main()
 char *a="HAI";
return 0;


void pointer parameter


Here PostInArrayNotFound is an overloaded function with parameter as follows

1.       Void pointer
2.       ArrayNotFound object(Since parameter of ArrayNotFound  constructor is char pointer call to PostInArrayNotFound("DD") will inturn call an ArrayNotFound   constructor when “void PostInArrayNotFound(const void *)” is not present in the program)
Here compiler has rights to call any one of the function. But since compiler can’t behave as it likes, standard said to follow the following rule.

System defined implicit conversion(void pointer) will take the high priority when compared to the user defined implicit conversion.

No comments:

Post a Comment