typedef
vector<string> pipeline; 
typedef
vector<pipeline> subPipelineStrings; 
subPipelineStrings* m_subPipelineStrings
m_subPipelineStrings = 
new subPipelineStrings(3); 
string *s1 = new string("s1");
string *s2 = new string("s2");
string *s3 = new string("s3");


for (int i = 0; i < m_subPipelineStrings ->size();++i)
{
pipeline &p = m_subPipelineStrings->at(i);
p.push_back(*s1) ;
p.push_back(*s2) ;
p.push_back(*s3) ;
}

The question : How do i destruct m_subPipelineStrings ?
Thank you in advance!

Ancient Dragon commented: Good going! Code tags on first post! :) +36

Recommended Answers

All 4 Replies

Stay away from those pointers.

lines 8-10: delete those lines

lines 16-18:

p.push_back(string("s1")) ;
p.push_back(string("s2")) ;
p.push_back(string("s3")) ;

With the above changes you don't have to worry about a destructor because the vector and string classes with destroy themselves.

It my need really...
Actually the strings s1,s2 are generated in some other function in dynamic way.
Please help me if you can

The code you posted appears to contain a memory leak. You don't have to worry about destroying those vectors because the vector class will destroy itself when the class or program terminates.

If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).

The code you posted appears to contain a memory leak. You don't have to worry about destroying those vectors because the vector class will destroy itself when the class or program terminates.

If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).

Thank you very much it worked!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.