Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:40:11+00:00 2026-06-07T11:40:11+00:00

I have a function in a GenericObject class that needs to get a struct

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:40:13+00:00Added an answer on June 7, 2026 at 11:40 am

    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.

    • have only one struct definition and allocate the needed matrix sizes at runtime
    • virtual accessor functions. Create a base struct with virtual functions that return the matrices, and only access the matrices through them.
    • template the function.

    If your structs’ members all have the same names, then just this should be enough:

    template <typename STRUCT_T>
    void GenericObject::SetTexture(struct STRUCT_T *_myStructOffset)
    {
    ...
    }
    

    obviously since it’s a template the function definition has to appear in your header file instead of the .cpp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function which takes in an parameter of a class called Triple, and
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
Inside my Controller i have function that runs after user clicks on item, which
This is not the clearest of question titles, sorry about that, but I will
I have function that have been colled in stored procedure. The function returns a
i have function like this. function load($name, $arg1, $arg2, $arg3, $arg4){ $this->$name = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.