Re: Unexpected C++ program result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux