i dont think you appreciate what im getting at.
-ok sorry not using code tags, but i did search.
anyway.
the problem is with the function template not the vector or the push_back function. ill explain a litte more...
i have three kinds of objects.
i have three vectors which hold pointers to objects.
i want to write a function that adds new objects to one of the vector
i dont want to write three functions, so i want to use a function template.
after a bit more playing around ive got this...
Code:
template < class T >
void MyFunc(std::vector < T > &aVector);
int main()
{
.
.
.
std::vector<MyClass *> vMyObject;
MyFunc(vMyObject);
.
.
}
template < class T >
void MyFunc(std::vector < T > &aVector)
{
T Obj; //pointer to object since T = MyClass*
aVector.push_back(Obj);
}
Now this works, but the trouble is the new object has no values because im not using the new keyword.
im creating a pointer to an object, and i know i need to get the "new" keyword in there somewhere...
Code:
T Obj;
Obj = new T; //this would work if T wasnt a pointer
aVector.push_back(Obj);
so there we go...
anymore ideas?