Basically, I have a class A that creates an array when built.
class A
{
public:
A (float height, float width, BYTE* data)
{
setsize(height,width);
mydata = CreateNewBuffer(sizes);
setdata(data);
}
~A()
{
}
void setsize(float height, float width)
{
sizes.cx = width;
sizes.cy = height;
}
BYTE* CreateNewBuffer (SIZE sImage)
{
return new BYTE [sImage.cx * sImage.cy];
}
void setdata(BYTE* data)
{
memcpy(threatdata,data,sImage.cx * sImage.cy);
}
}
I am creating a pointer to this class in a larger class:
A* mypointer;
which I initialize in the 3rd class after passing through the function:
3rdClass::instance()->myfunction(mypointer)
and inside the myfunction () function, I install a bool indicating that the class was built
mypointer = new A(height,width,data);
wasconstructed = true;
Now, the next time I go to the function pointer myfunction()
, I will check if the class has already been constructed, if it was, I want to delete it so that it creates a new one without losing memory.
What is the correct way to do this:
I tried basic things like <
if (3rdClass::instance()->checkifconstructed()){
delete mypointer;
mypointer = NULL;
}
But that does not work.