[comp.lang.c++] a beginner's question about container classes

gl8f@astsun7.astro.Virginia.EDU (Greg Lindahl) (06/01/91)

I would like to implement a set of small and beautiful container
classes like SmallTalk. Yes, I know that NIH exists.

I only let things derived from class ContainedObject to be within a
container class. I don't want all my objects to be a huge tree, just
the things that go in containers. Anyway, that's not what I'm asking.

When you're searching through a container, you need an equivalence
function. If I'm comparing a ContainedInt to a ContainedKitchenSink,
I'd like it to always be unequal. If I compare a ContainedInt to a
ContainedInt, I'd like a method in ContainedInt to be called.

What's the best way to do this? Can I directly get at something that
tells me what class an object is, or do I need to kludge it and create
a private member that's always at the same offset and test that?

I should mention that my only reference is the awful book "An Intro to
O-O Programming and C++". I should get a better reference :-/