class Base
{
protected:
int x;
public:
Base();
~Base();
virtual void displayx(){
cout << x << endl;
}
};
class Derived:public Base
{
public:
Derived();
~Derived();
void displayx(){
cout << x << endl;
}
};
int main()
{
Base * tanuki;
tanuki = new Derived;
//Unsure about these final lines of code.
std::map< string, vector<Base*>> myMap;
myMap.insert(make_pair("raccoon",vector<....*>()));
}
我希望能夠在myMap中存儲Derived的新實例。 然後用map中指定的標識符字符串調用displayx()函數。 我已經嘗試了多種東西,但我相信我已經碰到了一堵牆。使用派生類的向量圖
我該如何將基類'Base'的派生類'Derived'插入到我的矢量地圖中?
我認爲你需要清楚你想達到什麼目的。例如從什麼派生出來的? – ppaulojr
你想在地圖中的每個字符串的基*的*矢量*? – kfsone
@kfsone我仍然試圖找出那行代碼的東西。我是否應該將它作爲矢量 來實現我想要實現的目標? –
Xirol