回答編集履歴

1

newは不適当でした

2019/07/15 04:55

投稿

maisumakun
maisumakun

スコア145192

test CHANGED
@@ -4,10 +4,10 @@
4
4
 
5
5
  ```C++
6
6
 
7
- _equipmentList.push_back(new Equipment(&tmp));
7
+ _equipmentList.push_back(Equipment(&tmp));
8
8
 
9
9
  ```
10
10
 
11
11
 
12
12
 
13
- 下手にポインタを介するから煩雑になるわけで、`push_back`は`const T&`からのコピー、あるいは`T&&`からのムーブで格納されるので([cpprefjp](https://cpprefjp.github.io/reference/vector/vector/push_back.html))、そのまま`new`したオブジェクトを渡して問題ありません。
13
+ 下手にポインタを介するから煩雑になるわけで、`push_back`は`const T&`からのコピー、あるいは`T&&`からのムーブで格納されるので([cpprefjp](https://cpprefjp.github.io/reference/vector/vector/push_back.html))、そのまま一時オブジェクトを渡して問題ありません。