Passing to a Reference Argument by Value

前端 未结 7 921
名媛妹妹
名媛妹妹 2021-01-17 14:40

Consider this simple program:

vector foo = {0, 42, 0, 42, 0, 42};
replace(begin(foo), end(foo), foo.front(), 13);

for(const auto& i : foo) co         


        
7条回答
  •  一整个雨季
    2021-01-17 15:25

    vector foo = {0, 42, 0, 42, 0, 42};
    replace(begin(foo), end(foo), static_cast(foo.front()), 13);
    assert(equal(begin(foo), end(foo), begin({13, 42, 13, 42, 13, 42})));
    

提交回复
热议问题