By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

How to store instanses of a template class?

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
es******@yahoo.com wrote:
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.

Jul 19 '05 #2

P: n/a
es******@yahoo.com wrote in message news:<3d**************************@posting.google. com>...
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)

Jul 19 '05 #3

P: n/a
es******@yahoo.com wrote in message news:<3d**************************@posting.google. com>...
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)

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.