Explain Why Polymorphism Can't Be Used?

I

Immortal Nephi

You are able to enable polymorphism if you derived hundreds or
thousands of classes from base class. You use base class pointer to
select "general type" in derived classes before you create an object
as "specify type".

Please explain why you can't use polymorphism in diamond virtual
multiple inheritance.
 
J

James Kanze

[...]
- if you derive even hundreds of classes, you have a major design
issue. Abstracting the right thing (into delegation, metadata, or
_something_) might free up your concrete classes

In general, I totally agree with you, but there are exceptions.
I have one very simple interface (just one virtual function)
used to translate input data to UTF-8. There's one derived
class for each input encoding, and there have been literally
hundreds of different character encodings. (At present, I only
support about twenty, but I know of quite a few that I don't
support, and I'm pretty sure that there are even more that I
don't support.)

[...]
- prefer references to pointers. Think in terms of referring to the
base class, not pointing to it. Pointers are more wild and
dangerous than references

Yes and no. References don't support pointer arithmetic, so one
of the worst features of pointers has been eliminated. But it's
still far too easy to end up with dangling references. In cases
where smart pointers are appropriate, in fact, you should
probably avoid references in favor of the smart pointer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top