c++ - Different matrix structs passed by parameter -


"itemprop =" text ">

I have a function in a genericObject class that needs to be a struct as a parameter, but going to this struct All these structs are provided by one of their child classes to be the same member, but they will have different matrix sizes

This function meets the structs (obviously incorrect).

  GenericObject Zero :: SetTexture (struct * _myStructOffset) {for (int i = 0; i & lt; stateNumber; i ++) {(for int j = 0; j & LT; indexNumber; J ++) {SetTextureOffset (i, j, _mystructOffset [i] [j] -> xTex0, _myStructOffset [I] [J] -> xTex1, _myStructOffset [I] [J] - & Gt; yTex0, _myStructOffset [I] [J] -> yTex1, 100 / * _ myGenericOffset-> imageW * /, 100 / * _ myGenericOffset-> imageH * /); } GetMyAnimatedSprite () - & gt; Set animationist (); }}   

structure example:

  struct button data {float xTex0; Float yTex0; Float Extex 1; Float yTex1; } Button Offset 1 [3] [1];   

and should work in some way like this:

  Zero button :: SetTexture () {GenericObject :: SetTexture (& ButtonOffset1); }   

How can I do this?

Thanks in advance.

structs are all single members, so why is it redefined in children's classes?

I think the answer to this question "Different matrix sizes" means that they are a 2D that is array member who has a different static declaration shape, in other words, they are not a single member Are there.

Three solutions.

  • There is only one composition definition and the matrix size on the required allocated runtime
  • Create a base structure with the virtual accelerator function virtual functions that return the matrix, and through them only Access the matrix.
  • Templates the template.

    If the members of your strokes have all the same names, then it should only be sufficient:

      template & lt; Typename STRUCT_T & gt; Zero GenericObject :: SetTexture (struct STRUCT_T * _mystructOffset) {...}   

    Obviously because this is a template, the function definition is to appear in your header file instead of .cpp.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -