Placement new breaks consts and references?

后端 未结 4 1908
攒了一身酷
攒了一身酷 2020-12-20 15:29

Following the discussion on my answer to this question, apparently:

the following code is allowed

struct Foo {
    int x;
};

Foo f;         


        
4条回答
  •  旧巷少年郎
    2020-12-20 16:25

    If something is const-qualified, you're not supposed to modify it. Extending its lifetime is a modification with serious consequences. (For example, consider if the destructor has side-effects.)

提交回复
热议问题