In article <1151097822.149824.260330
@b68g2000cwa.googlegroups.com>,
fa***********@gmail.com
says...
typedef set::vector<Attribute> SetOfAttributes;
Or like this ?
class SetOfAttributes
{
typedef std::vector<Attribute *> TSet;
typedef TSet::const_iterator TConstIterator;
typedef TSet::iterator TIterator;
};
What good is class SetOfAttributes if all you put into it
is typedefs? All you're defining is names, so if you
don't want them to be visible globally, you probably want
to put them into a namespace rather than a class.
[ ... ]
Well, okay, but how should I declare my std::vector to accept many
instances of Attribute with different templates?
Ah, now we get to the crux of the situation: you want to
create an array of heterogeneous objects. The answer is
that you shouldn't even attempt to do that -- no matter
how you try to do it, it's going to cause a problem. Your
_only_ real choice is to make everything in the vector
the same type. They might be (smart) pointers to objects
of different types, but the things you actually put into
the vector really all need to be the same type.
From there you have a couple of choices: you can store
pointers to completely unrelated types, with some
intelligence to get the original type of object back when
you need it, or you can store a pointer to a base class,
and (when necessary) have it point at instances of
derived objects.
An entirely different possibility is to simply store the
different types of objects separately from each other. If
you have a relatively small set of types to deal with,
this may be the cleanest method available.
From the sound of things, your design may simply need
more thought. I'm not sure whether you're better off
doing that on your own, or posting more about the problem
here, and having us help out, but it sounds like right
now your problem goes far beyond mere syntax.
--
Later,
Jerry.
The universe is a figment of its own imagination.