C++ const_cast usage instead of C-style casts
问题 Why is the following?: const int i0 = 5; //int i1 = const_cast<int>(i0); // compilation error int i2 = (int)i0; // okay int i3 = 5; //const int i4 = const_cast<const int>(i3); // compilation error const int i5 = (const int)i3; // okay 回答1: const int i0 = 5; //int i1 = const_cast<int>(i0); // compilation error int i2 = (int)i0; // okay int i3 = 5; //const int i4 = const_cast<const int>(i3); // compilation error const int i5 = (const int)i3; // okay The compilation errors are caused because you