How to delcare a vector of a type which is a template class by itself?

K

Kai Wu

Hello,

Suppose a template class

template<typename T>
class A{
.......
};

now i wish to typedef a vector of class A, how it can be done?

typedef std::vector<template<class> A> MyVector;
typedef std::vector<template<class> A<T> > MyVector<T>;
.........

None of those works ... Please help
Thanks so much
 
L

Larry I Smith

Kai said:
Hello,

Suppose a template class

template<typename T>
class A{
.......
};

now i wish to typedef a vector of class A, how it can be done?

typedef std::vector<template<class> A> MyVector;
typedef std::vector<template<class> A<T> > MyVector<T>;
........

None of those works ... Please help
Thanks so much

I believe that you can only declare a vector of fully specified
templates, e.g.

typedef std::vector< A<int> > MyVectorI;

But I may be wrong.

You could also do something like this:

template <typename T>
class MyVector : public std::vector< A<T> >
{
//...
};

Then create one like this:

MyVector<char> vc;

Larry
 
S

Sharad Kala

Kai Wu said:
Hello,

Suppose a template class

template<typename T>
class A{
.......
};

now i wish to typedef a vector of class A, how it can be done?

typedef std::vector<template<class> A> MyVector;
typedef std::vector<template<class> A<T> > MyVector<T>;

As of now typedefs can't be templated directly. You could do the following
instead --
template<typename T>
class A{
typedef std::vector<A> MyVector;

};

Though this solution isn't quite the same as having a template typedef.

Sharad
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top