In the first place, don't access member variables of other classes directly. This is very bad practice. Your member variables should be private and you should declare methods (functions) to return the value. This prevents a caller from setting them to invalid values.
In the second place, why are the member variables "destroyed" when you reach that line? They shouldn't be. What is more likely is that you haven't initialised them.
You are using the default constructor to create the LoadImage object. Is this what you want, or do you want to specify a file path or a resource id, for example?
Do you have a default constructor that correctly initialises the member variables (probably to zero).
How about this, for example:
class LoadImage
{
public:
LoadImage()
: width(0),
height(0),
imgData(NULL)
{
}
LoadImage
(
const std::string& filePath
)
: width(0),
height(0),
imgData(NULL)
{
}
virtual ~LoadImage()
{
if (NULL != imgData)
{
imgData = NULL;
}
}
inline int GetHeight() const
{
return height;
}
inline int GetWidth() const
{
return width;
}
private:
int width;
int height;
BYTE* imgData;
};