Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

Destructor Called After Constructor

This topic is 2764 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!