Why compiler is calling first overloaded function not second one?

Consider following program.

#include <iostream>
void fun(const char a[]) {
    std::cout<<"function 1n"; 
    std::cout<<a<<'n';
}
void fun(char *a) {
    std::cout<<"function 2n"; 
    std::cout<<a<<'n';
}
int main() { 
    fun("string");
}

What should I change in the program so that second function gets called instead of first one?


Source: c++

Leave a Reply