Dependencies in Initialization Lists

前端 未结 3 1382
别跟我提以往
别跟我提以往 2021-02-12 14:23

Is this behavior well-defined?

class Foo
{
    int A, B;

    public:

    Foo(int Bar): B(Bar), A(B + 123)
    {
    }
};

int main()
{
    Foo MyFoo(0);
    re         


        
3条回答
  •  别那么骄傲
    2021-02-12 15:17

    Initialization is done in the order of appearance in the declaration, not the order you write it in the constructor.

    Look at this question, it's somewhat similar: Initializer list *argument* evaluation order

提交回复
热议问题