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

containers and template classes

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.