Reputation: 28227
I'm digging through some ancient code, originally built in C++ Builder 6. Littered through-out the code base is the following pattern, which, IMHO, segfaults as it should:
vector<int> x;
try {
... some run of the mill vector manipulation
} __finally {
delete &x;
}
The delete &x;
is really odd. As I understand it, the vector<int>
will only exist for the lifetime of the function it is contained within, so no need to call delete
on it.
Is there some sensible motivation behind this pattern, or is it just plain wrong?
Upvotes: 1
Views: 54
Reputation: 234825
It's certainly not standard C++.
A delete
should only be used if new
is used. Else the behaviour is undefined.
Upvotes: 4