I have a function in a GenericObject class that needs to get a struct as a parameter, but this struct is going to be provided by its child classes. All these structs have the same members, but they will have different matrix sizes.
This function get the structs (parameter obviously wrong):
void GenericObject::SetTexture(struct* _myStructOffset)
{
for (int i = 0; i < stateNumber; i++)
{
for (int j = 0; j < indexNumber; j++)
{
SetTextureOffset(i, j, _myStructOffset[i][j]->xTex0, _myStructOffset[i][j]->xTex1, _myStructOffset[i][j]->yTex0, _myStructOffset[i][j]->yTex1, 100/*_myGenericOffset->imageW*/, 100/*_myGenericOffset->imageH*/);
}
GetMyAnimatedSprite()->SetAnimationToList();
}
}
Struct example:
struct ButtonsData
{
float xTex0;
float yTex0;
float xTex1;
float yTex1;
}
ButtonOffset1[3][1]
;
And should work in some way like this:
void Button::SetTexture()
{
GenericObject::SetTexture(&ButtonOffset1);
}
How can I make it?
Thanks in advance.
If the structs all have the same members, then why redefine it in child classes?
I suspect that the answer is that “different matrix sizes” means that they have a 2D array member that is a different statically declared size, in other words they do NOT have the same members.
Three solutions.
If your structs’ members all have the same names, then just this should be enough:
obviously since it’s a template the function definition has to appear in your header file instead of the .cpp.