Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
割り当てられているが初期化されていないメモリ位置が与えられた場合、潜在的に高価な中間オブジェクトを構築せずに、オブジェクトをその位置に移動する (元のオブジェクトを破棄する) にはどうすればよいですか?
メモリ内でそれを移動構築するには、placement new を使用できます。
void * memory = get_some_memory(); Thing * new_thing = new (memory) Thing(std::move(old_thing));
自明でないデストラクタがある場合は、完了時に明示的に破棄する必要があります。
new_thing->~Thing();