What is the proper way to allow vectors of shared pointers to a derived class to get passed to a function which is expecting a vector of shared pointers to a base class without performing a copy?
Here is the code:
#include <string>
#include <vector>
#include <memory>
class Base {
public:
std::string Name;
};
using BaseList = std::vector<std::shared_ptr<Base>>;
class Derived : Base {
};
using DerivedList = std::vector<std::shared_ptr<Derived>>;
class BaseHandler {
public:
void process( BaseList list ) {
}
};
int main() {
BaseList list;
BaseHandler bh;
bh.process( list );
}
Code Link: http://ift.tt/1CmKKTj
EDIT: DOH!!! I posted the wrong one. Sorry about that...here is the shared_ptr one.
Aucun commentaire:
Enregistrer un commentaire