Thanks for the reply, but it *barely* worked.
The issue is this:
I have function fun1(){
X* Xinstant;
Xinstant = (X*) new X;
..
..
fun2(Xinstant);
}
fun2(Xinstant)
{
Xinstant->push_back(whatever) <---- I get a "what(): St9bad_alloc error"
}
I don't see what the problem is..
thanks!
k
First of all, the typecast you have for creating XInstant is unnecessary. The new operator automatically allocates memory for the object, calls its constructor, and returns a pointer to that object. In other words, the new operator is like a function that returns a pointer - in this case, a pointer of type X*. So you can redo this statement as
Next, are you making sure that, when you push_back(whatever), that 'whatever' is of type int? It would be bad if you were pushing back a double, for example, and this could produce a bad_alloc error (as the compiler allocating int memory, not double memory).