From what I understand, in the following code, explicit A(int a) should prevent A b('g'); to use the int constructor:
#include <iostream>
class A
{
public:
int x;
char *y;
A() : x(0) {}
explicit A(int a) : x(a) { std::cout<<"INT\n"; }
A(char *b) : y(b) { std::cout<<"C STRING\n"; }
};
int main()
{
A a(5); /// output: "INT"
A b('g'); /// output: "INT"
A c("Hello"); /// output: "C STRING"
}
However, A b('g'); uses the int constructor... Why?
Also, another question: If I write A(const char *b) instead of A(char *b), it gives me the following error: invalid conversion from 'const char*' to 'char*' [-fpermissive]. Why can't I convert a const char* to char*?