Examples of implicit type conversions (implicit calls to constructors) :

#include <iostream>
using namespace std;

class Point {
public:
    int x, y;
    Point(int x)
        : x(x) {}
};

void displayPoint(const Point& p) 
{
    cout << "(" << p.x << ")" << endl;
}

int main()
{
    displayPoint(1);
    Point p = 1;
}

Explicit keywords

Specifies that the constructor or conversion function (starting with C++11) is explicit, that is, it cannot be used for implicit conversion and copy initialization.

A constructor can no longer be called implicitly when it is explicit. In other words, previous code with explicit notation before Point(int x) will not be compiled.

#include <iostream> using namespace STD; class Point { public: int x, y; explicit Point(int x) : x(x) {} }; void displayPoint(const Point& p) { cout << "(" << p.x << ")" << endl; } int main() { displayPoint(1); Point p = 1; }

Effective c + + :

Constructors that are declared explicit are usually more popular than their non-explicit Cousins because they prohibit the compiler from performing type conversions that are not expected (and often not expected). Unless I have a good reason to allow the constructor to be used for implicit conversions, I declare it explicit. I encourage you to follow the same policy.