Sign in to follow this  

Destructor Called After Constructor

This topic is 2542 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

Hi,

I have the following C++ code:
glLibTexture2D texture = glLibTexture2D("../testdata/Image1.png",GLLIB_ALL,GLLIB_RGBA,GLLIB_FILTER,GLLIB_MIPMAP_BLEND);
"glLibTexture2D" inherits from a class "glLibInternal_texture". Putting breakpoints in the destructors of both "glLibTexture2D" and "glLibInternal_texture" shows that they are both called by the time the above line is completed.

I'm very confused by this, and the destructor is killing data that needs to be used later. Can someone explain what's going on?

Thanks,
-G

Share this post


Link to post
Share on other sites
The right-hand side is a temporary object that is constructed, used in the copy constructor for the left-hand side, and then is destroyed. Use instead


glLibTexture2D texture("../testdata/Image1.png",GLLIB_ALL,GLLIB_RGBA,GLLIB_FILTER,GLLIB_MIPMAP_BLEND);

Share this post


Link to post
Share on other sites
Ah thanks; that was the problem.

After some more investigation, this has shown an underlying problem in the code that requires a copy constructor to fix (not for the example above, but for other circumstances).

I've set up a copy constructor for the class, but for some reason, it is saying it doesn't have access to the class's private members.

Help? Thanks,
G

Share this post


Link to post
Share on other sites

This topic is 2542 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