I am new to C++, I was trying to deallocate an object with different ways. Here is my code:
class foo{
public:
int* bar;
foo(int N){
bar = new int[N];
}
~foo(void){
delete[] bar;
}
};
int main(int argc, char* argv[]){
foo* F = new foo(10);
delete F;
return 0;
}
This works perfectly, but if I write main like this:
int main(int argc, char* argv[]){
foo F = foo(10);
F.~foo();
return 0;
}
I will end up with an "glibc detected". I guess I should somehow deallocate the "bar" pointer since it was allocated during construction.
Thus my question is how can I deallocate an object like this? Thanks.