How to use Vectors and templates together

Hello,
I have these two classes
-------------------------------------------------
template<typename T> class X
{
public:
X(string A, T B); //constructor
.
.
.
};

--------------------------------------------------
#include "X.h"
template<typename T> class Y
{
public:
vector< X<T>* > VecX;
.
.
.
};
-------------------------------------------------
I want to add a cell to the vector VecX by push_back and keep in it a pointer to new object X, however I keep getting errors, I tried doing it like this:

VecX.push_back(new X<T>::X(A,B));

whats the problem? how should I write this?

Thanks
Last edited on
Hello,
where exactly are you trying to push_back() ? How are A and B defined? Why do you call the constructor of X explicitly? At a first glance, the call doesn't look too bad...
where exactly are you trying to push_back()


in a function belongs to Class Y, and its in public

How are A and B defined?


A is a string, B will be defined during runtime, and it can be unsigned or double.

Why do you call the constructor of X explicitly

At some point, regarding the user commands, I may have to build new object X (dynamically), so I'll push to the vector (which contains pointers to X) a new object which the constructor will build
Last edited on
B will be defined during runtime, and it can be unsigned or double.

It must be of type T. Could you please show a little more code (like the definition of A and B)?
Topic archived. No new replies allowed.