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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:17:26+00:00 2026-06-08T04:17:26+00:00

I have structure aa and I’m trying to run such code: aa * b

  • 0

I have structure aa and I’m trying to run such code:

aa * b = new aa;
aa * c = new aa;
c=b;
delete (b);
c.useSomeFunction

Can I use the object pointed to by c after destruction of b?

The same question in case of:

aa * b = new aa;
aa * c ;
c=b;
delete (b);
c.useSomeFunction
  • 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-08T04:17:27+00:00Added an answer on June 8, 2026 at 4:17 am

    The title of the question is misleading, because you don’t use an operator=() in your code. You only assign pointers which are built-in types.

    As pointed out before:

    In your first example, the pointer assignment yields a memory leak, as the object (*c) can no longer be deleted. Also you cannot call a function of (*b) (even if pointed to by c after deleting object (*b).

    In your second example you don’t get the memory leak. Note that in production code you should initialise every pointer with nullptr. Also here you cannot access a function of (*b) after deleting the object.

    the call to the function must be c->useSomeFunction() in order to by syntactically correct.

    What you probably want (and is suggested by the title) is to create a new object and assign the content of the old one to it. Something like:

    struct aa {
      aa():x(0),y(0){}
      aa& operator=(const aa& rhs);
      int foo(){return x-y;}
      int x;
      int y;
    };
    
    aa& aa::operator=(const aa& rhs){
      if (this == &rhs) {return *this;}
      x = rhs.x; 
      y = rhs.y;
      return *this;
    }
    
    int main(){
      aa *b = new aa();
      aa *c = new aa();
      *c = *b;
      delete(b);
      c->foo();
      delete(c);
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this structure, Can I use xpath on this to first locate the
I have a structure: typedef struct stock { const char* key1p2; // stock code
I have structure defined in some header (D3DXVECTOR3) How can I declare: static member
I have such structure of document: { _id : 4e76fd1e927e1c9127d1d2e8, name : ***, embedPhoneList
Say I have structure like: <ul id=a>text <li id=b>text</li> <li id=c>text</li> </ul> How can
I have code structure like that: var adjective = context.Adjectives.Find(11); //works var substantive =
I have a structure of this type (Ext 3.3.1): var page = new Ext.Viewport({
I have menu structure like below, <ul class=sub-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-34 id=menu-item-34><a
I have structure in Python code and in C code. I fill these fields
I have structure like this. <ul class=gallerylist> <li> <image ...> <input ...> </li> <li>

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.