Can anyone explain why the following code compiles? I expect it to get an error where the double
constant 3.3
can not be converted to int
, since I declare the constructor to be explicit
.
class A
{
public:
int n;
explicit A(int _n);
};
A::A(int _n)
{
n = _n;
}
int main()
{
A a(3.3); // <== I expect this line to get an error.
return 0;
}