In C++, a constructor labelled explicit is only ever called when named in the program. It may therefore not be used to match a call to a function with a different signature -- the constructor is only used when explicitly requested.

An example is in order. Suppose I have a class Histogram, which represents k-tuple frequencies in a block of text. It makes sense to have k as an argument to the constructor:

class Histogram {
private:
  // ...
public:
  Histogram(int k);
  // ...
};
It also makes sense to calculate entropy for the distribution that a Histogram represents, so I declare (and define) a function double entropy(Histogram);.

What happens if I call entropy(17) from my code? Well, it makes no sense (I defined entropy for distributions, not numbers), so you'd expect the type system to flag an error. Well, it doesn't. What happens instead is that the compiler constructs a temporary Histogram (for 17-tuples, naturally), and passes that to entropy.

To prevent this sort of gratuitous conversion from occurring, flag the constructor explicit.

Ex"pli*cit (?). [LL., an abbreviation of explicitus (est liber) the book (which anciently was a roll of parchment) is unfolded (and, of course, "finished"). See Explicit, a.]

A word formerly used (as finis is now) at the conclusion of a book to indicate the end.

 

© Webster 1913.


Ex*plic"it (?), a. [L. explicitus; p.p. of explicare to unfold: cf. F. explicite. See Explicate, Exploit.]

1.

Not implied merely, or conveyed by implication; distinctly stated; plain in language; open to the understanding; clear; not obscure or ambiguous; express; unequivocal; as, an explicit declaration.

The language of the charter was too explicit to admit of a doubt. Bancroft.

2.

Having no disguised meaning or reservation; unreserved; outspoken; -- applied to persons; as, he was earnest and explicit in his statement.

Explicit function. Math. See under Function.

Syn. -- Express; clear; plain; open; unreserved; unambiguous. -- Explicit, Express. Explicit denotes a setting forth in the plainest, language, so that the meaning can not be misunderstood; as, an explicit promise. Express is stronger than explicit: it adds force to clearness. An express promise or engagement is not only unambiguous, but stands out in bold relief, with the most binding hold on the conscience. An explicit statement; a clear and explicit notion; explicit direction; no words can be more explicit. An explicit command; an express prohibition. "An express declaration goes forcibly and directly to the point. An explicit declaration leaves nothing ambiguous."

C. J. Smith.

 

© Webster 1913.

Log in or register to write something here or to contact authors.