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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:30:36+00:00 2026-05-20T03:30:36+00:00

I have a scene class with member variables Image **images, int * xcoords, int

  • 0

I have a scene class with member variables Image **images, int * xcoords, int * ycoords. Now, I’m trying to overload my = operator.

I get the following memory errors (using valgrind)

Conditional jump or move depends on uninitialised value(s)
==6439==    at 0x406FCA: Scene::drawscene() const (scene.cpp:160)
==6439==    by 0x4084C1: main (testscene.cpp:50)

And the line in question from above (scene.cpp:160) is

if (images[i]!=NULL) 

So theyre saying that images was not initialized.

And so anywhere else drawscene() was called did not cause any problems, but I think because the = operator was used, it caused a problem.

Can anyone see any problems in my code that could cause this error?

  • 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-20T03:30:37+00:00Added an answer on May 20, 2026 at 3:30 am

    You need this:

            if(source.images[i]!=NULL) {
                images[i]=new Image;
                *images[i]=*source.images[i];
                xcoords[i]=source.xcoords[i];
                ycoords[i]=source.ycoords[i];
            } else {
                images[i] = NULL;
            }
    

    and that will solve your immediate problem. But really, you’re going about this the wrong way. As @Gman said, you should be using the copy-and-swap idiom.

    The reason to use the idiom is exception safety. If something throws an exception in the middle of that operator = (and there is plenty that can since it’s doing so much) you will be leaving the object in an undefined state, and that’s very bad. The copy and swap idiom lets you write an exception safe copy-constructor (which is still a little tricky) and then leverage it to build an assignment operator.

    As an added bonus, you get a working copy constructor and a swap function. The copy constructor is very handy for stuffing things in STL containers and passing or returning things by value. And the swap function is is pretty darned useful for users of your class, especially ones who would like to implement their own exception safe copy constructors and assignment operators.

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

Sidebar

Related Questions

Ok I have two classes: Image and Scene. Now in the Image header file,
I have a game which have 5 class/level.Each class contain almost same variables.Now i
I have code: class Scene def initialize(number) @number = number end attr_reader :number end
I can't figure out what is up with this. I have a Scene class
Right now for my game, I have a scene manager and it runs a
Hi I'm creating a water scene and have a class called drawWater. The class
I'm using VS2010. In the constructor of my non-compyable Scene class I have :
I have const struct aiScene *scene; declared in class. In the function where I
I have created a loading scene separate class derived from CCScene which I can
I have a class called GameScene, with is a subclass of a cocos2d Scene.

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.