- explicit 修饰构造函数时,可以防止隐式转换和复制初始化
- explicit 修饰转换函数时,可以防止隐式转换,但按语境转换除外
#include <iostream>using namespace std;struct A
{A(int) { }operator bool() const { return true; }
};struct B
{explicit B(int) {}explicit operator bool() const { return true; }
};void doA(A a) {}void doB(B b) {}