This is the current code (working) that I have. It works but for large number of A & B objects, it's not the most efficient. It's also not really heterogenous either. It's really just a storage of the parent class objects.
Expand|Select|Wrap|Line Numbers
- class A
- { … }
- class B:public A
- { … }
- vector<A*> combined;
- vector<A> list_A;
- vector<B> list_B;
- for(size_t i=0; i<list_A.size();i++)
- {
- combined.push_back(new A(list_A[i]));
- }
- for(size_t i=0; i<list_B.size();i++)
- {
- combined.push_back(new B(list_B[i]));
- }
Now, I still need to combined those two different vectos into a single one.
Something like this:
Expand|Select|Wrap|Line Numbers
- vector< boost::shared_ptr<A> > list_A;
- vector< boost::shared_ptr<B> > list_B;
- for(size_t i=0; i<list_A.size();i++)
- {
- combined.push_back(list_A[i]);
- }
- for(size_t i=0; i<list_B.size();i++)
- {
- combined.push_back(list_B[i]);
- }
vector< … > combined;
Following the original method, I thought about:
Expand|Select|Wrap|Line Numbers
- vector< boost::shared_ptr<A> > combined;
even though B inherits A, you can't just replace boost::shared_ptr<A> with boost::shared_ptr<B> directly right?