Home

Hi!

Gordan Krešić schrieb:
> void doAbstract(const std::list<Abstract *> &abstractList) {
> // something...
> }
>
> void doAbstract(const boost::shared_ptr<Abstract> &abstractPtr) {
> // something...
> }
>
> int main(int argc, char *argv[]) {
>
> std::list<Derived *> derivedList;
> doAbstract(derivedList); // does not work?

No. There is not std::list constructor (which is needed here) to convert
a list<Derived*> to a list<Abstract*>.

> boost::shared_ptr<Derived> derivedPtr;
> doAbstract(derivedPtr); // works...

Yes. shared_ptr has support for an appropriate conversion constructor.

But you can do:

void doAbstractOnce(Abstract* abstract) { ... }

std::list<Derived*> list;
std::for_each(
list.begin(), list.end(),
&doAbstractOnce
);

Frank

previous
next

Re: Basic problem with Inheritance
Re: Misleading wikipedia article on Python 3?
Is it a good idea to implement constructors with assignment operator?
Re: __contains__() : Bug or Feature ???
Re: Why :: ? Why not : ? Why not . ? <- less clutter ?!?
Niechciane i Zapomniane
Mimo Wszystko
Nasze Dzieci
Fundacja Avalon
Akogo