Search code examples
c++c++11initialization

complex<> using list initializer vs constructor?


I'm reading Stroustrup C++ 4th Ed. Page 162 Types and Declarations. Specifically, where the following is allowed to construct a complex<> object.

The book comments that case A is "use constructor". Is case A really a list initializer and the constructor method of initialization is performed in B or C?

#include <iostream>
#include <complex>
using namespace std;

int main(int argc, char *argv[])
{
    complex<double> z = { 0, 3.14 }; // A
    complex<double> h(0, 3.14); // B
    complex<double> i{0, 3.14}; // C

    return 0;
}

Solution

  • The effects are all the same for this case; objects are initialized by the constructor complex::complex(double, double).