【发布时间】:2017-04-06 02:29:10
【问题描述】:
#include <iostream>
struct int_wrapper
{
int i;
int_wrapper(int i = 0) : i(i) {}
};
struct A
{
int_wrapper i;
int_wrapper j;
A(int_wrapper i = 0, int_wrapper j = 0) : i(i), j(j) {}
};
int main()
{
A a;
a = {3};
// error: no match for ‘operator=’ (operand types are ‘A’ and ‘int’)
// a = 3;
std::cout << a.i.i << std::endl;
return 0;
}
我知道在进行隐式转换时不允许多次用户转换,但是,为什么使用大括号初始化列表可以实现双重用户转换?
【问题讨论】:
标签: c++ c++11 implicit-conversion list-initialization