Uniform initialization fails to copy when object has no data members

前端 未结 2 1244
-上瘾入骨i
-上瘾入骨i 2020-12-02 02:00

In updating some code to use uniform initialization, I thought it would be a drop-in modern substitue for the now \"old style\" parentheses style. I know this isn\'t always

2条回答
  •  醉梦人生
    2020-12-02 02:22

    This is a known bug and will hopefully be fixed in C++17 (not for C++14, see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1467). Your struct is an aggregate, so to initialize it with {someElement} there needs to be at least one data member, as you have discovered. Try providing an operator int(); and you will see it compiles.

提交回复
热议问题