473,412 Members | 2,306 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,412 software developers and data experts.

containers and template classes

if I have a template class declared as ff:

template <typename T>
class A {
public:
//usual ctors and dtor cut to save space
T& get( void ) ;
void set( const T&) ;

private:
T x ;
};
How I can I store such an object in a vector like this:

std::vector< A > vector_of_a ; //<- this is pseudocode

Jul 23 '05 #1
2 1069
Alfonso Morra wrote:
if I have a template class declared as ff:
It's not a template class. It's a class template.
template <typename T>
class A {
public:
//usual ctors and dtor cut to save space
T& get( void ) ;
void set( const T&) ;

private:
T x ;
};
How I can I store such an object in a vector like this:

std::vector< A > vector_of_a ; //<- this is pseudocode


You can't. std::vector requires _a_type_ as its first argument, not
a template. Think about it. What "object" are you going to store?
What is 'T'? If it's something concrete, like 'int', then you need
to specify it. If it's not anything concrete, then how would the
vector know how much storage to allocate for it?

V
Jul 23 '05 #2

"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
if I have a template class declared as ff:

template <typename T>
class A {
public:
//usual ctors and dtor cut to save space
T& get( void ) ;
should be:
T get() const;
void set( const T&) ;

private:
T x ;
};
How I can I store such an object in a vector like this:

std::vector< A > vector_of_a ; //<- this is pseudocode


The std::vector container can't guess what class A is storing. Try:

std:vector< A<int> > vector_of_n;
std:vector< A<double> > vector_of_d;

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Wolfgang Lipp | last post by:
<annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with the consent of their authors. -- _w.lipp </annotation> From:...
1
by: Prakash Bande | last post by:
Hi, I have a template class as below: template <class _T> class myclass{ public: myclass(){ obj = new _T();} _T* obj; _T* operator->() (return obj;} };
8
by: Simon Elliott | last post by:
Given a template function: template <class T> void foo(T& value) { // do something with value } Is there any way I can tell whether the type T is an STL container?
1
by: Mattias Brändström | last post by:
Hello! Sometimes I get the urge to write something like the following template (see the code below) to help me initialise stl containers. With this template I could: vector<int> v =...
2
by: jsnX | last post by:
i want a function object that is a) initialized with an STL container foo b) will search foo for an object of type foo::value_type here is my code: ...
7
by: BigMan | last post by:
Which is the preferred way to create a const container in general: 1. container_type< value_type > const; or 2. container_type< value_type const >?
8
by: Mark P | last post by:
Is there any way to forward declare STL container classes such as list, set, map, etc.? (My impression is that there isn't, since these are all defined in std.) Failing that, consider the...
15
by: Nindi73 | last post by:
HI If I define the class DoubleMap such that struct DoubleMap : public std::map<std::string, double>{}; Is there any overhead in calling std::map member functions ? Moreover are STL...
21
by: George Exarchakos | last post by:
Hi everyone, I'd like your help... Can we have a std::list<BASEwhere BASE be the base class of a class hierarchy? I want to add to this list objects that are inherited from BASE class but not...
3
by: massysett | last post by:
Greetings, Having classes with member objects that have STL containers of objects whose definitions are incomplete results in undefined behavior. See for example: ...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.