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

  • Home
  • SEARCH
  • 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 9152479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:03:29+00:00 2026-06-17T12:03:29+00:00

First, what i want to do is to resize a class’ array when it’s

  • 0

First, what i want to do is to resize a class’ array when it’s full by doing a “object++” but
I got a “Segmentation fault(core dumped)” error when executing a C++ program. The problem is inside the operator++ overloading method. It’s supposed to copy the contain of the first array in a temporary object (the operator= overloading is already done and works well), then to change the height and width of the array, and finally copy again the temporary object inside the object which is returned. When i comment “*this = *tmpPlateau ;” the array is resized but the contain is not copied. the Here is the code :

Plateau& Plateau::operator++() {

      // New sizes
      int newHauteur = this->height + 2 ; 
      int newLargeur = this->width + 2 ; 

      // Tableau temporaire avec le contenu du plateau actuel
      Plateau* tmpPlateau = this ;      

      // Actualisation des dimensions 
      this->height = newHauteur ; 
      this->width = newLargeur ;

      this->plateau = new Etat*[height] ; 
      for (int i = 0; i < height; i++) {

        plateau[i] = new Etat[width] ;

      }

      *this = *tmpPlateau ;     

      return *this ;
}

The operator= overloading method :

Plateau& Plateau::operator=(const Plateau& tab) {

      this->plateau = new Etat*[height] ; 
      for (int i = 0; i < height; i++) {

            this->plateau[i] = tab.plateau[i] ; 

       }

       Plateau(height, width) ;
}
  • 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-17T12:03:30+00:00Added an answer on June 17, 2026 at 12:03 pm

    I think the problem is twofold.

    Firstly, tmpPlateau is not a separate object. It’s just another pointer to *this:

      Plateau* tmpPlateau = this ;      
    

    Consequently, the following calls operator=() with *this as its argument:

      *this = *tmpPlateau ;   
    

    I suspect the crash is because your operator=() doesn’t handle self-assignment correctly.

    However, the real problem is that tmpPlateau needs to hold a copy of the object rather than a pointer to it.

    Finally, you’d find it much easier to implement your class if you used std::vector instead of an array. This would make it much easier to grow plateau.

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

Sidebar

Related Questions

I have an object which I first want to rotate (about its own center)
First I want to apologize for such a silly question but I'm quite new
I have a problem but first i want to know if im working on
First I want to describe my situation briefly. I have two classes, one MainClass
First I want to clearify that I mean by reverse engineering something like decompiling
At first I want to say: I couldn't find a support forum for this
I am trying to do this with MVC 3 EF Model first I want
Hello everyone my problem is very simple. Using entity framework code first I want
In our application, we receive messages from JMS Topic. First I want to know
First thing i want to say that it's not an easy question to explain,

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.