TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  INT#001Checked automatically with code checker

Synopsis:Non-copy-constructors that can be called with one argument shall be declared as explicit
Severity Level:2
Category:Class Interface


When using constructors with single arguments, these constructors need to be declared with the keyword explicit. This keyword prevents implicit type conversions for the arguments to the constructor.

explicit CTestClass(SHORT nValue);

This syntax prevents an implicit conversion from the float argument in the next example, which can cause undesirable side effects.

CTestClass TestClass = 3.2; // Does not work

This rule does not apply to copy-constructors, because they do not define type conversions. This rule does apply to constructors with N arguments, with N or N-1 default values. See also [OLC#007] and [CON#001].

Literature References:
ISC++ Rec. 7.18