STLを使い始めたばかりで、うさぎのクラスがあると言って、今はうさぎの軍隊を作っています...
#include <vector>
vector<rabbit> rabbitArmy (numOfRabbits,rabbit());
//Q1: these rabbits are on the heap right?
rabbit* rabbitOnHeap = new rabbit();
//Q2: rabbitOnHeap is on the heap right?
rabbit rabbitOnStack;
//Q3: this rabbit is on the stack right?
rabbitArmy.push_back(rabbitOnStack);
//Q4: rabbitOnStack will remain stored on the stack?
//And it will be deleted automatically, though it's put in the rabbitArmy now?
Q4は私が最も懸念しているものですが、軍隊にウサギを追加するために常に新しいキーワードを使用する必要がありますか?
Q5:軍隊にウサギを追加するより良い方法はありますか?
rabbitArmy.push_back(*rabbitOnHeap);