Sign in to follow this  

C++ explicit destructor call on built-in types

This topic is 3845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've tried searching for information on this. I don't understand why this compiles okay:
template <typename Type>
void Destroy (Type* object)
{
	object->~Type ();
}

int* j;
Destroy (j);

Ignoring lack of initialization etc., why does that appear to compile okay with a built-in type? If that compiles, then why don't these compile? :
template <typename Type>
Type Double (Type object)
{
	return object.operator+ (object);
}

int j;
Double (j);
j.~int ();

Share this post


Link to post
Share on other sites
Apologist answer: Because of how STL allocation interfaces work, it's useful to be able to do an explicit destructor call without caring whether the type actually has a destructor.

Realistic answer: C++ is somewhat schizophrenic. Deal with it.

Share this post


Link to post
Share on other sites

This topic is 3845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this