[Fwd: Re: [xsd-users] polymorphism plus sequence equals slicing objects]

Boris Kolpackov boris at codesynthesis.com
Mon Sep 10 04:17:16 EDT 2007


Hi Kroizman,

Kroizman Guy <kroiz at hyperroll.com> writes:

> what I am trying to do
>
> auto_ptr<Base> c;
>
> if(condition1())
> {
> 	c = new Derived1();
> }
> if(condition2())
> {
> 	c = new Derived2();
> }
>
> root.item().push_back( c );
>
> can I do that?

Yes, try changing it to:

root.item().push_back( *c );


> because what happen is that the overloaded push_back in sequence is not
> called, instead the push_back of vector gets call. and I guess that is
> not good.

This can't happen because the underlying vector's push_back functions
are not part of the sequence's interface.


Boris




More information about the xsd-users mailing list