Debug Assertion Failed! Line: 52 Expression: _BLOCK_TYPE_IS_VALID (pHead-> nBlockUse)

#pragma once #ifndef _WARGAME_H #define _WARGAME_H #include "warplayer.h" #include "deck.h" #include <iostream> const int NUMPLAYERS = 2; //number of players in the game class WarGame { private: WarPlayer* arrPlayer[NUMPLAYERS]; //the array of players Deck *decks = new Deck(); public: WarGame(WarPlayer *name1, WarPlayer *name2); void printStatus(); WarGame(const WarGame& other); ~WarGame(); WarPlayer* startGame(int rounds); WarPlayer* tie(Card* c1, Card* c2); }; #endif // !_WARGAME__H WarGame::~WarGame() { arrPlayer[0]->~WarPlayer(); cout<< "\n" << endl; arrPlayer[1]->~WarPlayer(); cout<< "\n" << endl; delete[] arrPlayer[0]; //delete first player delete[] arrPlayer[1]; //delete second player } 

Closed due to the fact that off-topic participants Grundy , Vartlok , zRrr , D-side , PashaPash 12 Apr '16 at 19:27 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Grundy, Vartlok, zRrr, D-side, PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Well what are you doing!

  1. Twice you call WarPlayer destructor! when deleting, the destructor is called automatically!

  2. And it is not clear that by applying delete [] to a single element - or does your arrPlayer point to a dynamically allocated array? Here you have some kind of a terrible discrepancy - you would show what WarPlayer and how the arrPlayer array is arrPlayer - without this, it is difficult to advise how to proceed.

So you get, most likely, when you re-release the memory of a damaged internal structure ...