For example, I have a class
struct A
{
A(int i, double d) {...}
private:
int m_i;
double m_d;
};
and a function with an argument A
void f(A a);
And I can use initializer list to call the function
f( A{1, 3.14} );
How to make the following simple version also works?
f( {1, 3.14} );
The call of the function with the initializer list will work. You should do nothing special.:)
The call would not be compiled if the constructor had function specifier explicit
. In this case you have to use the previous call of the function
f( A{1, 3.14} );
using functional notation of casting the initializer list to an object of type A.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With