473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to store instanses of a template class?

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
3 1688
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nico Massi | last post by:
Hi NG! I have a class A that should store a vector of pointers to objects of class B. But class B contains a template argument and each of the stored objects in class A could have a different...
1
by: Tino | last post by:
From Stroustrup( TC++PL, Appendix C.13 ) I thought that this was the way (and the only way perhaps) to have a common static member for all classes generated from a template. Though compiling this...
4
by: Sebastian Faust | last post by:
Hi, I have 4 questions related to templates. I wanna do something like the following: template<typename T> class Template { public: Template_Test<T>()
4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
12
by: James Brown | last post by:
Hi all, Having problems designing a template-class. I'll describe my scenario first then show what I've come up with so far: Need a class to provide pointer/array-like access to an area of...
7
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void...
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
2
by: garfunkelorama | last post by:
Hi all, I'm sure there is a simple solution to this but it's beyond me. Please can someone help? You have a class like this: class A { public: template<typename T>
9
by: Adam Nielsen | last post by:
Hi all, I'm a bit confused about the syntax used to access a nested template class. Essentially I have a bunch of class types to represent different types of records in a database, and I want...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.