What is the 'explicit' keyword and why is it used for constructors?

Last updated 21 June 2026

  • explicit stops a constructor (or conversion operator) from being used for implicit conversions, so Widget b = 5; and f(5) fail while Widget a(5); works.

  • It prevents surprising silent conversions, since any single-argument constructor otherwise doubles as an implicit conversion.

  • Default to marking single-argument constructors explicit. Since C++11 it also applies to multi-arg (brace-list) constructors and conversion operators.

  • https://internshala.com/blog/cpp-coding-interview-questions/
  • https://www.geeksforgeeks.org/cpp/how-to-prevent-implicit-conversions-in-cpp/
All C++ interview questions