C++ Logo

std-discussion

Advanced search

Re: Safety critical C++ inheritance?

From: Richard Bamford <richardbamford1_at_[hidden]>
Date: Wed, 17 Apr 2024 21:32:52 +0000
Thanks Chris!

I was confusing tagged unions and classes, i have to use virtual functions with classes to avoid the heap i believe?

Thank you!
Richard B.
________________________________
From: Chris Ryan <chrisr98008_at_gmail.com>
Sent: 17 April 2024 22:18
To: std-discussion_at_lists.isocpp.org <std-discussion_at_[hidden]>
Cc: Tiago Freire <tmiguelf_at_[hidden]>; Richard Bamford <richardbamford1_at_[hidden]>
Subject: Re: [std-discussion] Safety critical C++ inheritance?

A derived object is just an object, with the base object being the first thing in the object footprint. No allocation required. There are no special heap mechanisms involved.

I believe the OP is confusing inheritance with dynamic-polymorphism that requires the base to provide the interface, using the virtual mechanism.

You can use objects from multiple object pools (each pool of different object types, each object derived from the same base), or multiple static objects (each object derived from the same base), then be able to treat the objects polymorphically, using a base pointer. No allocation required.

Chris++;

On Wed, Apr 17, 2024 at 1:52 PM Tiago Freire via Std-Discussion <std-discussion_at_[hidden]<mailto:std-discussion_at_[hidden]>> wrote:

You can use the stack?

Not sure I understand your question. As far as I know heap memory is not a requirement for inheritance.



From: Std-Discussion <std-discussion-bounces_at_[hidden]<mailto:std-discussion-bounces_at_[hidden]>> On Behalf Of Richard Bamford via Std-Discussion
Sent: Wednesday, April 17, 2024 22:24
To: std-discussion_at_[hidden]<mailto:std-discussion_at_[hidden]>
Cc: Richard Bamford <richardbamford1_at_[hidden]<mailto:richardbamford1_at_[hidden]>>
Subject: [std-discussion] Safety critical C++ inheritance?



Hi,



The MISRA C++ programming standards and many safety critical applications are unable to use heap memory without filing deviations. Is there any way that programs aiming to follow those standards can use inheritance in C++ without using heap memory?



Thank you,

Richard B.

--
Std-Discussion mailing list
Std-Discussion_at_[hidden]<mailto:Std-Discussion_at_[hidden]>
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2024-04-17 21:32:55