This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Unexpected C++ program result


On 9 May 2012 20:10, klperez wrote:
>
> Hello Mattia, I am glad your question was sort of answered. Given his answer
> it seems to me that gcc breaks the rules of polymorphism, because it does
> not allow multiple inherited objects to be treated like their base class.

No, GCC doesn't break anything.

A Final "is a " Base.

But an array of FInal is not an array of Base.

> Clearly one should not have Final objects be stored in a dynamically
> allocated array of base classes, but is there a way to store them in a
> different way without leaking memory?

Yes, of course:

Final* p = new Final[2];

delete[] p;

> For example could one use a std
> vector, which stores three Final objects, and then calls clear when it comes
> time to delete them?

Yes, of course.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]