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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:10:09+00:00 2026-06-01T12:10:09+00:00

I keep getting the error in VS 2100 CRT detected that the application wrote

  • 0

I keep getting the error in VS 2100 “CRT detected that the application wrote to memory before start of heap buffer”

Can anyone help? My int Main is all the way on the bottom. The error occur when the delete [] command is run on the operator= function

#include "intset.h"
const int MAXINITIALSIZE = 5;
int IntSet::numOfArray = 0;

IntSet::IntSet(int a, int b, int c, int d, int e)
{
    numOfArray++;
    int tempArray[] = {a, b, c, d, e};
    size = determineHighest(tempArray) + 1; //determines largest int
    cout << "size is " << size << endl;

    arrayPtr = new bool[size]; //creates array of bool

    for (int i = 0; i < size; i++) //fill bool array 
    {
        arrayPtr[i]= false;  //arrayptr is a bool pointer created in the header
    }   

    for (int i = 0; i < MAXINITIALSIZE; i++)
    {
        arrayPtr[tempArray[i]]= true;
    }

        for (int i = 0; i < size; i++)
    {
        cout << &arrayPtr[i] << endl;
    }
}
IntSet::IntSet(const IntSet &intsetObject)
{
    numOfArray++;
    size = intsetObject.size;

    arrayPtr = new bool[size];

    for (int i = 0; i < size; i++)
    {
        if (intsetObject.arrayPtr[i])
            arrayPtr[i] = intsetObject.arrayPtr[i];
    }
}
IntSet::~IntSet()
{
    --numOfArray;
    delete [] arrayPtr;     
    arrayPtr = NULL;
}

int IntSet::determineHighest(int tempArray[])
{
    int temp = tempArray[0];    
    for (int i = 1; i < MAXINITIALSIZE; i++)
    {
        if (tempArray[i] > temp)
            temp = tempArray[i];
        else
            continue;       
    }
    return temp;
}

IntSet& IntSet::operator=(const IntSet &intsetObject) //ask about IntSet&
{
    cout << "inside operator=" << endl;
    if (&intsetObject != this)
    {
        for (int i = 0; i < size; i++)
        {
            cout << &arrayPtr[i] << endl;
        }
        delete [] arrayPtr;   //HEAP ERROR HERE!
        for (int i = 0; i < size; i++)
        {
            cout << &arrayPtr[i] << endl;
        }
        size = intsetObject.size
        arrayPtr = new bool[size]();
        for (int i = 0; i < size; i++)
        {
            if (intsetObject.arrayPtr[i])
                arrayPtr[i] = intsetObject.arrayPtr[i];
        }
    }
    return *this;
}
ostream& operator<<(ostream &output, const IntSet &intsetObject)
{
    output << "{ ";
    for (int i = 0; i < intsetObject.size; i++)
    {
        if (intsetObject.arrayPtr[i] == true)
        {
            output << i << " ";
        }
        else 
            continue;
    }
    output << "}";
    return output;
}


//main

#include "intset.h"

int main() {

    IntSet object2(9);   

    IntSet object4(3,6);

    object4 = object2;

   return 0;
}
  • 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-01T12:10:10+00:00Added an answer on June 1, 2026 at 12:10 pm

    This can only happen if arrayPtr is accessed with a negative index. I suspect your defaults for a,b,c,d,e are -1 in the declaration for IntSet::IntSet, so it is writing to arrayPtr[-1] in the set-true loop. Check for tempArray[i] >= 0 there.

    Also, you can’t print the array after you have deleted it, so you should remove those lines after the delete, although they should be “harmless” in that only garbage will be printed, but who knows – the OS could release the page containing the array and it could segfault your program.

    Finally, you should not test if (intsetObject.arrayPtr[i]) in the copy & = operators. Otherwise all “false” elements in the source array become uninitialized in the destination array (new bool[size] does not initialize the array to all false).

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

Sidebar

Related Questions

I keep getting error: no type or storage class may be specified here before
When I try to run mvn (Apache Maven, that is), I keep getting error
With the following code, I keep getting error C2535 when I compile. It's complaining
I'm trying to code some stuff for a game but I keep getting error
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I keep getting this error when I try to commit a group of executed
I keep getting this error when I try to call Find() public void findTxt(string
I keep getting this error all over the place where I only have jquery

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.