C++ implicit conversion

Oct. 23, 2015, 12:34 a.m.

Given:

struct Wat {
    Wat(int i) {};
};
void foo(Wat w) {};

C++ allows you to do:

foo(1);

C++ will use the constructor to create the object upon invocation. This is called implicit conversion, a better name for which should be Completely Unexpected Default C++ Behavior #827125. I did not know about this until an interviewer recently asked me about the explicit keyword, which is used to suppress this implicit conversion behavior.

Much palms were faced.