1
期待基類的列表我有以下類傳遞派生類的列表的功能在C++
class Parent {
virtual void doStuff() = 0;
};
class Child : public Parent {
void doStuff() {
// Some computation here
}
};
和我有具有以下簽名的函數。
void computeStuff(std::vector<boost::shared_ptr<Parent> >);
提供,我可以修改我的代碼(包括函數簽名),什麼是傳遞函數computeStuff
指針到Child
對象名單的最佳方式?
從本質上講,我想下面的代碼片段來編譯和運行
std::vector<boost::shared_ptr<Child> > listOfChilds = getList();
computeStuff(listOfChilds);