Can you explicitly call destructors when dynamically allocating memory?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
class example
{
int * dyn;
public:
example()
{
dyn = new int[20000];
}
~example()
{
delete [] dyn;
}
};
int main()
{
example cplusplus;
cplusplus.~example();
return 0;
}
|
No.
delete will be called twice on dyn causing undefined behavior.
Generally, you shouldn't have to call deconstructors anyway.
Topic archived. No new replies allowed.