0

Possible Duplicate:
What does the explicit keyword in C++ mean?

what does the keyword explicit mean?

Community
  • 1
  • 1
lital maatuk
  • 5,921
  • 20
  • 57
  • 79

1 Answers1

5

C++ constructors that have just one parameter automatically perform implicit type conversion. For example, if you pass an int when the constructor expects a string pointer parameter, the compiler will add the code it must have to convert the int to a string pointer. However, you might not always want this automatic behavior.

You can add explicit to the constructor declaration to prevent implicit conversions. This forces the code to either use a parameter of the correct type, or cast the parameter to the correct type. That is, if the cast is not visibly expressed in code, an error will result.

explicit (C++)

Sudantha
  • 15,684
  • 43
  • 105
  • 161