Thursday, 15 January 2015

c++ - How to make initializer list implicitly convert to the class? -



c++ - How to make initializer list implicitly convert to the class? -

for example, have class

struct { a(int i, double d) {...} private: int m_i; double m_d; };

and function argument a

void f(a a);

and can utilize initializer list phone call function

f( a{1, 3.14} );

how create next simple version works?

f( {1, 3.14} );

the phone call of function initializer list work. should nil special.:)

the phone call not compiled if constructor had function specifier explicit. in case have utilize previous phone call of function

f( a{1, 3.14} );

using functional notation of casting initializer list object of type a.

c++ initializer-list

No comments:

Post a Comment