Getting started with C++ explicit

 When developing cryptocurrency, you will often see a bunch of explicit keywords in C++ code. This modifier is actually not a new thing, but it is rarely seen in the Taiwanese industry.

His initial function was to restrict others from using the class to obediently use the constructor. Later, the new standard also extended other functions, which will not be discussed in this article.

Here is an example:

class Integer{
public:
    int data;
    explicit Integer(int i) {data = i;}
};

int main() {
    Integer i1 = 10; // Compile Error!
    Integer i2(10); // Call constructive OK!
    cout << i2.data << endl;
    return 0;
}

Comments

Popular posts from this blog

Getting started with Gradle-Grovvy language foundation

Gradle configuration Spring multi-project test