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 ?
You have to do that yourself just before the vector is destroyed (or earlier
of course) (probably in the destructor of your class).
That is the price you have to pay for not using something like.
std::vector<std::string>
Regards, Ron AF Greve
http://informationsuperhighway.eu
<irina...@gmail.com> wrote in message
news:62a3ee44-4e4c-417c...@z19g2000vbz.googlegroups.com...
I thought you were storing pointers (my mistake).
in this case you can immediately destroy them since the vector makes a copy
of them.
However apparently there is no need to dynamically allocate them first just
push the strings right away.
p.push_back( "string" ) ;
Regards, Ron AF Greve
http://informationsuperhighway.eu
"Ron AF Greve" <me@localhost> wrote in message
news:4a22bfd3$0$182$e4fe...@news.xs4all.nl...
Simple:
delete m_subPipelineStrings;
But you also should delete the objects *s1, *s2, and *s3 at some
point:
delete s1;
delete s2;
delete s3;
You should ask yourself why you allocated the string objects *s1, *s2,
*s3, and the vector *m_subPipelineStrings on the heap.
Also, make sure you understand what vector<string>::push_back really
does. A vector of T manages its own /copies/ of T. push_back will copy-
construct a new element from the given one. So, you could have just
written the following:
typedef vector<string> pipeline_t;
vector<pipeline_t> pipelines (3);
if (!pipelines.empty()) {
pipeline_t & p = pipelines[0];
p.push_back("s1");
p.push_back("s2");
p.push_back("s3");
}
for (int i=1, s=pipelines.size(); i<s; ++i) {
pipelines[i] = pipelines[0]; // copy-assigns vector
}
Cheers!
SG
10x