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 9024523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:02:12+00:00 2026-06-16T06:02:12+00:00

The following is an abridged version of my Sprite class: class Sprite { struct

  • 0

The following is an abridged version of my Sprite class:

class Sprite
{
    struct SpriteState {
        Vector3 position;
        int width, height;
        double rotation, scaling;
    };
    std::map<int, SpriteState> stateVector;
}

I’d like to create a SpriteState object through a member function that looks something along the lines of the following:

SpriteState newSpriteState(
        Vector3 position = stateVector.rbegin()->second.position, 
        int width = = stateVector.rbegin()->second.width, 
        int height = = stateVector.rbegin()->second.height, 
        double rotation = stateVector.rbegin()->second.rotation, 
        double scaling = stateVector.rbegin()->second.scaling)
    { SpriteState a; a.position = position; a.width = width; a.height = height; a.rotation = rotation; a.scaling = scaling; return a; }

I get the following error:

a nonstatic member reference must be relative to a specific object

The basic idea behind the class itself is to store the various states of the sprite as it changes so that I can easily recover to a previous state if needed.

However, in most cases the Sprite is only updated with new position values while width, height, rotation, and scaling stays pretty much the same – which means I only change the position value while popping up and saving again references from the last state saved for the other values.

I’d hence like to be able to set default values for the function so that I don’t have to laboriously write the same values repeatedly.

Any possible ideas on implementation?

  • 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-16T06:02:14+00:00Added an answer on June 16, 2026 at 6:02 am

    You should make a copy of the SpriteState, and then modify it:

    SpriteState newSpriteState(stateVector.rbegin()->second);
    newSpriteState.width = someNewWidth;
    return newSpriteState;
    

    Every struct and class have by default a copy constructor of the following form:

    ClassName(const ClassName&);
    

    Which by default copies the data in the class/struct.

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

Sidebar

Related Questions

following situation: <body> <div style=position:fixed; width:100%>[place holder for header]</div> <div style=position:relative;width:100%;margin-top:100px>[content]</div> </body> I need
I have the following setup, abridged for brevity: public abstract class AuditableEntity { public
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
I added radio button tags to the following JSP (abridged and anonymized) in a
I'm using the following markup (abridged) to display a list of person objects in
I have the following (abridged schema) - 3 tables - user, job, job_type TABLE:
I have the following very simple and (abridged) classes: // IEntry interface public interface
Following are the two approaches: constructor with all the class properties Pros: I have
following is the code listed in MainClass.java. public class MainClass { public static void
My role provider looks like the class below (abridged). I am running on IIS

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.