Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) explicit

 

explicit is a keyword to disable converting constructors.

 

 

 

 

 

Example

 

The example below will not compile, due to the explicit keyword written in the constructor of Test:

 

struct Test
{
  explicit Test(const int x) {}
};

int main()
{
  Test t_i = 0;
}

 

The line in main needs to call a converting constructor, because an int is not a Test (that is: they are different data types).

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict