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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:46:26+00:00 2026-06-17T05:46:26+00:00

I have a problem with c++ pointers I’m a C# and VB.NET programmer, but

  • 0

I have a problem with c++ pointers

I’m a C# and VB.NET programmer, but I have converted to C++ recently, so I’m a C++ new newbie somehow

Now I’m writing a subtitle editor and I have two classes a subtitle Paragraph class containing a list of pointers to all of its lines

And a subtitle line class containing a pointer to its parent paragraph (to invoke a method in parent when line has changes )

In the subtitle paragraph class, when I delete the list of pointer to the sub lines they don’t get deleted

I tested this by trying to use the pointers after deleting them and call some functions and they work!

I also used “System Monitor” in Ubuntu to tell how much memory does my application use before and after allocating space for the pointers
and I found that it gets increased after allocating memory but the space doesn’t get freed after I delete the pointers

So I have a couple of questions:

1- can I have two classes each of which referencing to each other?

2- when I replace a pointer in one of the two classes with a reference does the same problem still exists

3- if I have two classes each of which referencing to each other how can I break this reference manually

I know I can use a shared pointer or weak pointer classes but I want to do it manually first

Here is a sample of my two classes to demonstrate the problem in my application

#include <iostream>
#include <stdio.h>

class B;

class A
{
    public :
      void setB(B *b){_b = b;cout << "set B" << endl;}
      ~A();
    private:
    B *_b;

};
class B
{
    public :
        void setA(A *a){_a = a;cout << "set A" << endl;}
        ~B(){cout <<"B is dieing" << endl;/*delete _a;*/}
    private:
        A *_a;

};

A::~A(){cout << "A is dieing" << endl;delete _b;}

int main()
{
    getchar(); // two have some time to know how much memory does my application use before allocaing space for pointers

    A *a = new A;
    B *b = new B;

    a->setB(b);
    b->setA(a);

    getchar();// two have some time to know how much memory does my application use after deallocaing the space

    delete a;
    delete b;

    // but here,after deleting it, it's still there, not deleted! I can use it
    a->setB(b);

    getchar();
    return 0;
}

thanks in advance

Yasser Sobhy

  • 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-17T05:46:27+00:00Added an answer on June 17, 2026 at 5:46 am

    After having deleted an object, you could make the pointers point to NULL so you would not be able to use both of them anymore.

    When you free a memory space in the heap, blocks are considered as free so they will be overwritten on any further memory allocation. But if not, you can still use it as you saw. But it is obviously not a good practice at all.

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

Sidebar

Related Questions

I have a problem that I really can't understand. I'm a newbie C programmer,
I have a problem with a template and pointers ( I think ). Below
I have a problem creating a std::map<int, int> from a vector of pointers, called
I am having a new little problem; I have a little pointer called: int
I have a big problem because i dont understand how the pointers really work
I have a problem. I need to clone objects class containing pointers. An example
I have a problem with enterprise library 5. It's writing to the event log
I'm writing a relatively big project in C++ and have a problem with object
I have a problem with my pointers and structures in C (I know, I
i have a specific problem with pointers and references, with std::vector and std::string. Some

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.