title: Purpose of Explicit Default Constructors
body: <p>I recently noticed a class in C++0x that calls for an explicit default constructor.  However, I'm failing to come up with a scenario in which a default constructor can be called implicitly.  It seems like a rather pointless specifier.  I thought maybe it would disallow <code>Class c;</code> in favor of <code>Class c = Class();</code> but that does not appear to be the case.</p>
  <p>Some relevant quotes from the C++0x FCD, since it is easier for me to navigate [similar text exists in C++03, if not in the same places]</p>
  <blockquote>
  <p>12.3.1.3 [class.conv.ctor]</p>
  <p>A default constructor may be an explicit constructor; such a constructor will be used to perform default-initialization or value initialization (8.5).</p>
  </blockquote>
  <p>It goes on to provide an example of an explicit default constructor, but it simply mimics the example I provided above.</p>
  <blockquote>
  <p>8.5.6 [decl.init]</p>
  <p>To default-initialize an object of type T means:</p>
  <p>— if T is a (possibly cv-qualified) class type (Clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);</p>
  <p>8.5.7 [decl.init]</p>
  <p>To value-initialize an object of type T means:</p>
  <p>— if T is a (possibly cv-qualified) class type (Clause 9) with a user-provided constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);</p>
  </blockquote>
  <p>In both cases, the standard calls for the default constructor to be called.  But that is what would happen if the default constructor were non-explicit.  For completeness sake:</p>
  <blockquote>
  <p>8.5.11 [decl.init]</p>
  <p>If no initializer is specified for an object, the object is default-initialized;</p>
  </blockquote>
  <p>From what I can tell, this just leaves conversion from no data.  Which doesn't make sense.  The best I can come up with would be the following:</p>
  <pre><code>void function(Class c);
  int main() {
    function(); //implicitly convert from no parameter to a single parameter
  }
  </code></pre>
  <p>But obviously that isn't the way C++ handles default arguments.  What else is there that would make <code>explicit Class();</code> behave differently from <code>Class();</code>?</p>
  <p>The specific example that generated this question was <code>std::function</code> [20.8.14.2 func.wrap.func].  It requires several converting constructors, none of which are marked explicit, but the default constructor is.</p>