desctructor of a vector

Dear Cplusplus' users,

I create and use the following vector:

std::vector< bool > component_select(1);
component_select[0]=true;

And now I would like to use its destructor. I have tried different options such as:

~component_select();
or
~component_select;
or
component_select.~Vector();
or
std::vector< bool > ~component_select;

but nothing seems to work.

I would be really grateful if someone could help me.
Thanks in advance.
Best,
Isi.
> And now I would like to use its destructor.

Why do you want to do that? The destructor would be invoked by the implementation when the life time of the object is over.

To remove all elements, use component_select.clear() ;
Thank-you for your answer.

On one hand, and if I wanted to release memory and I wanted to eliminate it by myself because I knew when the life time of the object is over, couldn't I do it?

On the other hand, I wanted to use the destructor because I wanted to define it again with more elements, I mean:

std::vector< bool > component_select(1);
component_select[0]=true;
.
.
.

Using its destructor , that I don't know how to call it, I would do:

std::vector< bool > component_select(3);
component_select[2]=true;
.
.
.

Thanks in advance.
Best,
Isi.
> I wanted to release memory and I wanted to eliminate it by myself

1
2
component_select.clear() ;
component_select.shrink_to_fit(); // C++11 

will (usually) release allocated memory.


std::vector<bool>().swap(component_select); will (always) release allocated memory.


> I wanted to define it again with more elements

Read this tutorial first: http://www.mochima.com/tutorials/vectors.html
Dear JLBorges,

thank-you for your answer and your recommendation.

Best,
Isi.
Topic archived. No new replies allowed.