Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why doesn C++ have a universal class Object?

class object universal
0
10 Posted

Why doesn C++ have a universal class Object?

0

• We don’t need one: generic programming provides statically type safe alternatives in most cases. Other cases are handled using multiple inheritance. • There is no useful universal class: a truly universal carries no semantics of its own. • A “universal” class encourages sloppy thinking about types and interfaces and leads to excess run-time checking. • Using a universal base class implies cost: Objects must be heap-allocated to be polymorphic; that implies memory and access cost. Heap objects don’t naturally support copy semantics. Heap objects don’t support simple scoped behavior (which complicates resource management). A universal base class encourages use of dynamic_cast and other run-time checking. Yes. I have simplified the arguments; this is an FAQ, not an academic paper.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.