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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:53:24+00:00 2026-06-18T07:53:24+00:00

After I compile with MSVC, my program triggers an assertion failure at runtime: _CrtlsValidHeapPointer(pUserData)

  • 0

After I compile with MSVC, my program triggers an assertion failure at runtime: _CrtlsValidHeapPointer(pUserData) , but the code looks ok to me…

class A
{
    int a;
public:
    A();
    A(int);
    virtual ~A();
    void setA(int);
    int getA();
    virtual void function()=0;
};

class B : virtual public A
{
    int b;
public:
    B();
    B(int,int);
    void setB(int);
    int getB();
    void function();
};

class C : virtual public A
{
    int c;
public:
    C();
    C(int,int);
    void setC(int);
    int getC();
    void function();
};

class D :public B,public C
{
    int d;
public:
    D();
    D(int,int,int,int);
    void setD(int);
    int getD();
    void function();
};

int _tmain(int argc, _TCHAR* argv[])
{
    A **p = new A*[4];
    int i;
    for(i=0;i<4;i++)
    {
        p[i]=new D(4,3,12,1);
    }
    for(i=0;i<4;i++)
    {
        p[i]->function();
    }
    for(i=0;i<4;i++)
    {
        delete p[i]; //the assertion fails when attempting to delete p[1]
    }
    delete[] p;
    system("pause");
    return 0;
}

What’s wrong with my code?

  • 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-18T07:53:25+00:00Added an answer on June 18, 2026 at 7:53 am

    You need a virtual destructor in A. It doesn’t have to do anything here, but it must be declared as virtual.

    In general, if you delete an object of a derived type through a pointer to a base type, the base type must have a virtual destructor.

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

Sidebar

Related Questions

i am a learner of 'C' and written a code, but after i compile
int i; int main() { return i; } After -static compile readelf -l shows
I'm trying to compile/run my program (which is working fine on Windows/MSVC) on Fedora/gcc.
Why does the following code fail to compile, while the two examples after compile
I have a simple question. I know that after compile a program when I
I'm sorry, but I can't understand why this doesn't work. After compile, I receive
I start to learn asm using fasm, unfortunately after compile code below I get
F# code targeted for xbox360 using xna does not compile after I convert the
Are there methods to obfuscate during/after compile that are automated?
I do tutorial in following link: Java RMI Tutorial After I compile successfully three

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.