派生クラスを持つ抽象クラスがあり、STL データ構造クラスを使用しない場合、オブジェクトの動的配列をポリモーフィックに作成するにはどうすればよいですか? (ベクトル、リストなど)
オブジェクトの静的配列
TwoDimensionShape *shapes[2];
shapes[0] = &Triangle("right", 8.0, 12.0);
shapes[1] = &Rectangle(10);
抽象クラスのオブジェクトを作成できないため、これができないことはわかっています。
cin >> x;
TwoDimensionShape *s = new TwoDimensionShape [x];
編集:
ニックのおかげで、これはうまくいきます:
int x = 5;
TwoDimensionShape **shapes = new (TwoDimensionShape*[x]);