Re: trait technique?
From: Nate Barney (natebarney_at_nospam.adelphia.net)
Date: 12/19/04
- Next message: Dave Rahardja: "Returning ptr to a virtual member function of a base class"
- Previous message: BjoernJackschina: "set off WinExplorer"
- In reply to: Jonathan Mcdougall: "Re: trait technique?"
- Next in thread: Tom Widmer: "Re: trait technique?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 19 Dec 2004 14:48:26 -0500
Jonathan Mcdougall wrote:
> Patrick Guio wrote:
>
>> Oops, my fault, it actually works... But I have another question: is
>> there a way to have a container such as map or vector that would
>> contain pointers of different specialisations of the template (a kind
>> of polymorphic pointer for template class)?
>
>
> A container cannot contain different types. A vector of int will always
> store ints. Since a class template is not a type (it is a family of
> types), you cannot use it as an element type for a container.
>
> template <class T> struct S;
>
> std::vector< S > v; // illegal
> std::vector< S* > v; // illegal
>
> std::vector< S<int> > v; // ok
> std::vector< S<int>* > v; // ok
This may or not be useful to the OP, but you can do this:
template <class T> struct S;
template <class T2>
struct S2
{
std::vector<S<T2> > v;
std::vector<S<T2>*> v2;
};
- Next message: Dave Rahardja: "Returning ptr to a virtual member function of a base class"
- Previous message: BjoernJackschina: "set off WinExplorer"
- In reply to: Jonathan Mcdougall: "Re: trait technique?"
- Next in thread: Tom Widmer: "Re: trait technique?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|