Used to suppress automatic implicit conversions of constructors.
structa{A (int) { }//Conversion ConstructorsAint,int) { }//Conversion Constructors (C++11) operator BOOL()Const{return true; }}; structb{ExplicitBint) { } ExplicitBint,int) { } Explicit operator BOOL()Const{return true; }}; intMain () {A A1=1;//OK: Copy initialization selection a::a (int)A A2 (2);//OK: Direct initialization select A::A (int)A A3 {4,5};//OK: Direct list initialization Select A::A (int, int)A A4 = {4,5};//OK: Copy list initialization selection a::a (int, int)A a5 = (a)1;//OK: Explicit transformation for static_cast if(A1);//ok:a::operator bool () BOOLNA1 = A1;//OK: Copy initialization selection a::operator bool () BOOLNa2 = static_cast<BOOL> (A1);//Direct initialization of the Ok:static_cast//B B1 = 1; //ERROR: Replication initialization does not consider b::b (int)B B2 (2);//OK: Direct initialization select B::B (int)B B3 {4,5};//OK: Direct list initialization Select B::B (int, int)//B b4 = {4, 5};//Error: Replication list initialization does not consider b::b (int,int)b b5 = (b)1;//OK: Explicit transformation for static_cast if(B2);//ok:b::operator bool ()//bool nb1 = b2;//ERROR: Replication initialization does not consider b::operator bool () BOOLNB2 = static_cast<BOOL> (b2);//Direct initialization of the Ok:static_cast}
"C + + note" explicit specifier