Title
Definition of “converting constructor”
Status
cd3
Section
11.4.8.2 [class.conv.ctor]
Submitter
Niels Dekker

Created on 2011-07-03.00:00:00 last changed 131 months ago

Messages

Date: 2012-02-15.00:00:00

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

Date: 2011-08-15.00:00:00

Proposed resolution (August, 2011):

  1. Change the example in 11.4.8.2 [class.conv.ctor] paragraph 1 as follows:

  2.   struct X {
          X(int);
          X(const char*, int =0);
          X(int, int);
      };
    
      void f(X arg) {
        X a = 1;          // a = X(1)
        X b = "Jessie";   // b = X("Jessie",0)
        a = 2;            // a = X(2)
        f(3);             // f(X(3))
        f({1, 2});        // f(X(1,2))
      }
    
  3. Change the example in 11.4.8.2 [class.conv.ctor] paragraph 2 as follows:

  4.   struct Z {
        explicit Z();
        explicit Z(int);
        explicit Z(int, int);
      };
    
      Z a;                       // OK: default-initialization performed
      Z a1 = 1;                  // error: no implicit conversion
      Z a3 = Z(1);               // OK: direct initialization syntax used
      Z a2(1);                   // OK: direct initialization syntax used
      Z* p = new Z(1);           // OK: direct initialization syntax used
      Z a4 = (Z)1;               // OK: explicit cast used
      Z a5 = static_cast<Z>(1);  // OK: explicit cast used
      Z a6 = { 3, 4 };           // error: no implicit conversion
    
Date: 2012-09-24.00:00:00

Although the normative wording of 11.4.8.2 [class.conv.ctor] paragraph 1 defining a converting constructor says

A constructor declared without the function-specifier explicit specifies a conversion from the types of its parameters to the type of its class.

implying that a constructor with multiple parameters can be a converting constructor, it would be helpful if the example contained such a constructor.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2012-11-03 00:00:00adminsetstatus: dr -> drwp
2012-09-24 00:00:00adminsetmessages: + msg4011
2012-02-27 00:00:00adminsetmessages: + msg3826
2012-02-27 00:00:00adminsetstatus: ready -> dr
2011-07-03 00:00:00admincreate