• 13
• 15
• 19
• 27
• 9

# Destructor Called After Constructor

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

## 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 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 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 on other sites
Post the relevant code.