Is it defined behavior to reference an early member from a later member expression during aggregate initialization?

前端 未结 4 1543
别跟我提以往
别跟我提以往 2020-12-03 00:54

Consider the following:

struct mystruct
{
    int i;
    int j;
};

int main(int argc, char* argv[])
{
    mystruct foo{45, foo.i};   

    std::cout <<         


        
4条回答
  •  眼角桃花
    2020-12-03 01:31

    how can I get the initial behavior (if it was well-defined behavior) with a user-defined constructor?

    Passing parameter by reference for that parameter which refers to previously initialized parameter of being constructed object, as follows:

     mystruct(int i, int& j):i(i),j(j)
    

提交回复
热议问题