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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:52:34+00:00 2026-05-20T12:52:34+00:00

Basically I have a class A which creates an array upon construction. class A

  • 0

Basically I have a class A which creates an array upon construction.

class A
{
public:
A (float height, float width, BYTE* data)
{
    setsize(height,width);
    mydata = CreateNewBuffer(sizes);
    setdata(data);     
}


~A() 
{

}
void setsize(float height, float width)
{
    sizes.cx = width;
    sizes.cy = height;
}

BYTE* CreateNewBuffer (SIZE  sImage)
{
    return new BYTE [sImage.cx * sImage.cy];
}

void setdata(BYTE* data)
{
    memcpy(threatdata,data,sImage.cx * sImage.cy);
}

}

I create a pointer to this class in bigger class:

A* mypointer;

which I initialize in a 3rd class after passing it through a function:

3rdClass::instance()->myfunction(mypointer)

and inside the function myfunction() I set a bool indicating the class was constructed

mypointer = new A(height,width,data);
wasconstructed = true;

Now the next time I come to the passing the pointer to the function myfunction(), I check if the class was already constructed, if it was, I want to delete it so that it creates a new one without memory loss.

What is the proper way to do this:

I tried basic stuff like,

if (3rdClass::instance()->checkifconstructed()){
    delete mypointer; //(or even delete [] mypointer but then i get heap corruption)
    mypointer = NULL;
}

But that does not seem to work.

  • 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-20T12:52:34+00:00Added an answer on May 20, 2026 at 12:52 pm

    I assume that mydata is a member of your class (otherwise, what is mydata in the 7-th line of your code?)

    So, the dynamic array is a member of your class. If you want to destroy it when the containing object is destroyed, you should do exactly that: order the destruction of your member in the destructor of your class. Something like:

    ~A() 
    {
      delete [] mydata;
    }
    

    Now, when you invoke delete mypointer it will invoke the destructor of the class, which will destroy the array.

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

Sidebar

Related Questions

I have a byte array of around 10,000 bytes which is basically a blob
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
Basically, I have a class with 2 methods: one to serialize an object into
So I basically want to have a static method in my AR class to
I basically have a page which shows a processing screen which has been flushed
I have a Course class which contains collection of CourseItems . Each CourseItem has
I have an array which I retrieve from some other source. This array then
I have a view called send_confirmation email - which basically sends emails. I want
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I am looking in to ways to enable a site to basically have something

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.