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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:14:32+00:00 2026-05-23T07:14:32+00:00

Hey so i’m making a function that gathers up sprites that you wanna keep

  • 0

Hey so i’m making a function that gathers up sprites that you wanna keep on screen, and
then “Check()s” them to make shure they stay, making them bounce of the edge of the screen otherwise.

I have defined a struct inside my class (‘Object’) which holds a refrence to the sprite, and whether it’s still outside the screen or not.
(as so the reflect() function isn’t called again before the sprite actually returns to being inside the screen)

I have three questions regarding the following code:

  • Will saving a refrence to a sprite in my Object struct allow me to reach the original sprite, and not just a copy when calling reflect()?

  • Why is the ‘Object’ Struct underlined in red, saying Error: implicitly generated constructor for class "OnScreenCheck::Object" cannot initialize.

  • In the Constructor, i create an Object instance, and pass it on into the Objects vector. I would think since i pass it on to the vector the vector would make a copy of it and save it, but i’m also wondering if the instance would be destroyed after the Constructors done, screwing something up. Will it Work?

Thanks for any help! Here’s the Functor:

class OnScreenCheck
{
public:
    struct Object{
        mySprite& Sprite;
        bool OffScreen;};

    void AddObject(mySprite& aSprite){
        Object newObject;
        newObject.Sprite= aSprite;
        newObject.OffScreen= false;
        Objects.push_back(newObject);
    };

    void Check(){
                // make sure box1 stays on the screen
        for(int I=0; I< Objects.size(); I++){
            //sprite has gone to high or to low
            bool yColl (Objects[I].Sprite.Side(mySprite::top)>=ScreenHeight 
              || Objects[I].Sprite.Side(mySprite::bottom)<=0);
            //sprite has gone to far left or right
            bool xColl (Objects[I].Sprite.Side(mySprite::left)<=0 
              || Objects[I].Sprite.Side(mySprite::right)>ScreenWidth);

            if(Objects[I].OffScreen==false){
                if(yColl){
                    Objects[I].OffScreen= true;
                    Objects[I].Sprite.Reflect(180);}
                if(xColl){
                    Objects[I].OffScreen= true;
                    Objects[I].Sprite.Reflect(90);}
            }
        }
    };

EDIT: also, my intentions with struct Object are not to have a public data type that belongs to OnScreenCheck, but to make a data type only usable by OnScreenCheck, as it saves these “objects” into the vector Objects. It is simply meant to organize the Data in OnScreenCheck. How can i make it like this, and so i don’t have to initialize a Object rightaway in the OnScreenCheck constructor?

  • 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-05-23T07:14:33+00:00Added an answer on May 23, 2026 at 7:14 am

    Will saving a refrence to a sprite in my Object struct allow me to reach the original sprite, and not just a copy when calling reflect()?

    References need to be initialize at the time of creation and they remain bound to the type object they are alias to So Saving a reference to sprite will always keep pointing to the same sprite object, any attempt to make it alias to something else will result in an error.

    Why is the ‘Object’ Struct underlined in red, saying Error: implicitly generated constructor for class "OnScreenCheck::Object" cannot initialize.

    You need to provide a constructor for OnScreenCheck which will appropriately initialize Object member, especially the reference member to sprite. The error is specifically because references MUST be initialized at time of creation.

    In the Constructor, i create an Object instance, and pass it on into the Objects vector. I would think since i pass it on to the vector the vector would make a copy of it and save it, but i’m also wondering if the instance would be destroyed after the Constructors done, screwing something up. Will it Work?

    The vector will save a copy of the object and will not be destroyed unless you explicitly ask the vector to do so through vector functions, unless ofcourse your object has some pointer types.

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

Sidebar

Related Questions

Hey there, i am trying to make a little app that will serve multiple
Hey there, I'm at the moment trying to make a product management application. The
Hey guys, I have a little button functionality that is not erring, but also
Hey, today I tried to create a photoshop automation that saves me an area
Hey, I'm trying to make an Address book for my site and I was
Hey guys, I just started learning C++ and I have this code that I
hey i got a contnet type that i made and i want to twweak
Hey I'm trying to creare a link that passes the link's text directly to
Hey, I am Just Learning CoffeeScript and I Keep getting Errors. Here is my
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)

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.