STL Vectors, pointers and classes

Posted by anubis9 on Stack Overflow See other posts from Stack Overflow or by anubis9
Published on 2010-03-20T19:11:33Z Indexed on 2010/03/20 19:21 UTC
Read the original article Hit count: 316

Filed under:
|
|
|

Hey!

Let's say i have 2 classes:

class Class1
{
public:
std::vector<CustomClass3*> mVec;
public:
Class1();
~Class1()
{
  //iterate over all the members of the vector and delete the objects
}
};

class InitializerClass2
{
private:
Class1 * mPtrToClass1;
public:
InitializerClass2();
void Initialize()
{
    mPtrToClass1->mVec.push_back(new CustomClass3(bla bla parameters));
}
};

Will this work? Or the memory allocated in the InitializerClass2::Initialize() method might get corrupted after the method terminates?

Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about pointers