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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:51+00:00 2026-05-20T10:19:51+00:00

I compiled & ran the code pasted below and surprisingly it worked without errors.

  • 0

I compiled & ran the code pasted below and surprisingly it worked without errors. (g++/linux)
How can a deleted object have some members still available ? Is it a normal behaviour ?

#include <iostream>

using namespace std;

class chair {
    public:
    int height;
    int x;
    int y;

    chair() {
        before = last;
        if(last!=NULL)
            last->after = this;
        else
            first = this;
        last = this;
        after = NULL;
    }

    ~chair() {
        if(before != NULL)
            before->after = after;
        else
            first = after;
        if(after != NULL)
            after->before = before;
        else
            last = before;
    }

    chair* before;
    chair* after;
    static chair* first;
    static chair* last;
};
chair* chair::first;
chair* chair::last;

int main() {
    chair *room = NULL;
    int tempx = 0;
    int tempy = 1;

    while(tempx<=3) {

        tempy = 1;
        while(tempy<=3) {
            room = new chair();
            room->x = tempx;
            room->y = tempy;
            tempy++;
        }

        tempx++;
    }

    room = chair::first;
    while(room!=NULL) {
        cout << room->x << "," << room->y << endl;
        delete room;
        room = room->after;
    }
}
  • 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-20T10:19:52+00:00Added an answer on May 20, 2026 at 10:19 am

    What you are doing is undefined behavior you are accessing a deleted object. The data you are looking at is still available and the area of memory where that information is stored hasn’t been overridden yet but nothing is stopping that from happening.

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

Sidebar

Related Questions

Why the assignment without '&' is compiling in the following code? I compiled the
Consider the following code: int main() { int *p; ++((int){5}); //compile without err/warning &((int){5});
Yesterday I ran into a g++ (3.4.6) compiler problem for code that I have
I've compiled & installed a mysql-5.1.59 on a x86_64 linux server. First I set
My client has a compiled ASP.NET 2.0 application that was compiled & deployed a
I compiled 2 different binaries on the same GNU/Linux server using g++ version 4.2.3.
I compiled the following code as a shared library using g++ -shared ... :
Pre-compiled headers seem like they can save a lot of time in large projects,
I have started to play around with boost python a bit and ran into
I compiled my trayicon utility c++ code in visual studio 2005 express edition and

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.