How to store instanses of a template class?

E

estrmich

I have a template class, say template<typename T> class A {...}. Now,
in the program I instantiate several As of different types: A<int>,
A<double>, A<string> etc. How can I store them in a container?

Thanks.
 
R

Rolf Magnus

I have a template class, say template<typename T> class A {...}. Now,
in the program I instantiate several As of different types: A<int>,
A<double>, A<string> etc. How can I store them in a container?

You can't. They are distinct types that don't have anything to do with
each other, at least for the compiler. You can put pointers to them
into a container if you derive them all from a common polymorphic base
class.
 
S

Siddhu T Nalwad

I have a template class, say template<typename T> class A {...}. Now,
in the program I instantiate several As of different types: A<int>,
A<double>, A<string> etc. How can I store them in a container?

Thanks.

Make use of Standard Template Library (STL)
 
S

Siddhu T Nalwad

I have a template class, say template<typename T> class A {...}. Now,
in the program I instantiate several As of different types: A<int>,
A<double>, A<string> etc. How can I store them in a container?

Thanks.

Make use of Standard Template Library(STL)
 

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,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top