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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:18:43+00:00 2026-06-14T23:18:43+00:00

Possible Duplicate: C++ delete – It deletes my objects but I can still access

  • 0

Possible Duplicate:
C++ delete – It deletes my objects but I can still access the data?

I would like to check if the following simple code has memory leak. In the function, it deletes a pointer and assigns a new object to this pointer. Is this legal? Under g++ compiler, even I deletes the test pointer, I can still access its member, which looks weird for me.

class cTest{
public:
  cTest(double _m){
    m=_m;
}
  ~cTest(){}

  double m;
};

void function (cTest * test){
  delete test;
  std::cout<<test->m<<std::endl;
  test= new cTest(1.2);
}
int main(){
  cTest *t = new cTest(0.1);
  std::cout<<t->m<<std::endl;
  function (t);
  std::cout<<t->m<<std::endl;
  delete t;
  return 0;
}

it prints out

0.1

0.1

1.2

  • 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-14T23:18:44+00:00Added an answer on June 14, 2026 at 11:18 pm

    Whenever you access a pointer after its lifetime has ended (eg. stack allocated object or after a delete) you stumble into undefined behavior, which is even worse than just an error because it may work and suddenly crash just when it decides to.

    The pointer is not valid anymore, data is still there because every unnecessary operation is not done in C++, that’s why in your situation it works.

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

Sidebar

Related Questions

Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: C++ delete - It deletes my objects but I can still access
Possible Duplicate: What's the best way to delete all data from a table? Clear
Possible Duplicate: Any reason to overload global new and delete? In c++ you can
Possible Duplicate: Can we delete an SMS in Android before it reaches the inbox?
Possible Duplicate: SQL Delete: can't specify target table for update in FROM clause I
Possible Duplicate: how to delete item from listView? I fetch data from Database in

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.