V
Venn Syii
I've searched all the forums but cannot find an answer to this question.
I do the following:
vector<MyClass*> myClassList;
Later in the program I try to add to myClassList with a .push_back(...)
I get an "out of memory" runtime error. I know I'm not out of memory
because normal vectors such as vector<int> a, still work, and still work
fine.
I've tried the following .push_back's
1) myClassList.push_back(new MyClass)
2) myClassList.push_back(new MyClass())
3) MyClass *Temp = new MyClass;
myClassList.push_back(Temp)
I have also tried changing the vector to
vector<MyClass> myClassList;
And have tried .push_back(..) in many different ways with it also. No luck,
still "out of memory" runtime error.
MyClass is defined as follows:
class MyClass
{
AnotherClass* AClass;
int a;
int b;
char * a;
char *b;
MyClass() {};
~MyClass() {};
void Create() {AClass = new AnotherClass;};
void Destroy() {if(AClass) delete(AClass); AClass = NULL};
}
I've also tried changing AnotherClass* AClass to AnotherClass AClass and
still the same problem.
Questions:
1) What could be causing the vector to show an "out of memory" error?
2) All the tutorials I've read use simple types in their vectors... what is
the proper way to use vectors with created classes and pointers?
Best Regards,
Venn
I do the following:
vector<MyClass*> myClassList;
Later in the program I try to add to myClassList with a .push_back(...)
I get an "out of memory" runtime error. I know I'm not out of memory
because normal vectors such as vector<int> a, still work, and still work
fine.
I've tried the following .push_back's
1) myClassList.push_back(new MyClass)
2) myClassList.push_back(new MyClass())
3) MyClass *Temp = new MyClass;
myClassList.push_back(Temp)
I have also tried changing the vector to
vector<MyClass> myClassList;
And have tried .push_back(..) in many different ways with it also. No luck,
still "out of memory" runtime error.
MyClass is defined as follows:
class MyClass
{
AnotherClass* AClass;
int a;
int b;
char * a;
char *b;
MyClass() {};
~MyClass() {};
void Create() {AClass = new AnotherClass;};
void Destroy() {if(AClass) delete(AClass); AClass = NULL};
}
I've also tried changing AnotherClass* AClass to AnotherClass AClass and
still the same problem.
Questions:
1) What could be causing the vector to show an "out of memory" error?
2) All the tutorials I've read use simple types in their vectors... what is
the proper way to use vectors with created classes and pointers?
Best Regards,
Venn