Object creation order in braced init list

后端 未结 3 1462
情书的邮戳
情书的邮戳 2021-01-08 00:40
#include 

struct A
{
    A() { std::cout << \"(A::A)\"; }
};

struct B
{
    B() { std::cout << \"(B::B)\"; }
};

struct C
{
    templat         


        
3条回答
  •  失恋的感觉
    2021-01-08 01:08

    Why in first braced init list objects are created in right-to-left order?

    No. It is left-to-right. Your compiler has bug which is why it is evaluating right-to-left. GCC (4.8) is known to have this bug. Do you use GCC?

    Why parentheses in second case revert this order?

    Same. Left to right. In this case, comma operator comes into picture, which evaluates operands left-to-right.

提交回复
热议问题