teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

書き間違いを修正しました

2020/11/25 14:41

投稿

gemfighter
gemfighter

スコア38

title CHANGED
File without changes
body CHANGED
@@ -207,17 +207,11 @@
207
207
 
208
208
  int main(){
209
209
  //直線用インスタンス(この配列に要素入れる)
210
- shared_ptr<StraightLine> p1(new StraightLine)[2];
210
+ shared_ptr<StraightLine> straightine(new StraightLine)[2];
211
211
 
212
212
  //直線出力用インスタンス
213
- std::vector<std::shared_ptr<Bottom*>> bases;//全部入れるテーブル
213
+ std::vector<std::shared_ptr<Bottom>> bases;//全部入れるテーブル
214
- try {
215
- straightine2 = new StraightLine;
214
+ shared_ptr<StraightLine> straightine2(new StraightLine);
216
- }
217
- catch (std::bad_alloc& e) {
218
- // メモリ確保に失敗
219
- std::cout << e.what() << std::endl;
220
- }
221
215
 
222
216
    //ここの処理で入れる
223
217
  for(int i = 0; i < 2; i++){
@@ -229,7 +223,7 @@
229
223
  bases.push_back(straightine);
230
224
 
231
225
  //もともとはここでポインタのアドレスをインクリメントしていた。
232
- *straightine++;
226
+
233
227
 
234
228
  }
235
229
 
@@ -241,15 +235,13 @@
241
235
  for (auto it = std::begin(bases); it != std::end(bases); ++it)
242
236
  {
243
237
  //直線出力
244
- if (dynamic_cast<StraightLine*>(*it) != 0)
238
+ if (dynamic_cast<StraightLine>(*it) != 0)
245
239
  {
246
240
  straightine2 = dynamic_cast<StraightLine*>(*it);
247
241
  straightine2->LK();
248
242
  }
249
243
  }
250
244
 
251
- //ここでstraightineとstraightine2をdeleteしたい
252
-
253
245
  return 0;
254
246
  }
255
247
  ```