C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2009, 03:54 PM   #1
Registered User
 
Join Date: Sep 2006
Location: vancouver wa
Posts: 216
Heap corruption Detected Error

I am trying to de allocate the memory i created. However, in the destructor i am getting a Heap coruption Detected Error

In reference to: delete [] items;

I have also tried to comment out the other pointers and it still does it..

Code:
#pragma once

#include <ostream>

using namespace std;

class quack
{
public:
	quack(int capacity);
	~quack(void);
	bool pushFront(const int n);	// push an item onto the front
	bool pushBack(const int n);		// push an item onto the back
	bool popFront(int& n);			// pop an item off the front
	bool popBack(int& n);			// pop an item off the back
	void rotate(int r);				// "rotate" the stored items (see note below)
	void reverse(void);				// reverse the order of the stored items
	int	itemCount(void);			// return the current number of stored items

private:

     int front;
	 int back;
	 int maxsize;
	 int count;
	
	struct item						// definition of each item stored by the quack
	{
		int		n;
	};
	item		*items;	            // pointer to storage for the circular array
	item        *frontPtr;
	item        *backPtr;
	item        *reversePtr;			// pointer to storage for the circular array

public:
	friend ostream& operator<<(ostream& out, quack& q);
	friend ostream& operator<<(ostream& out, quack::item& i);
};
Code:
quack::quack(int capacity): maxsize(capacity+1), front(capacity-2), frontPtr(NULL), backPtr(NULL), 
back(0), count(0), items( new item[capacity])
{


	frontPtr = new item;
	backPtr = new item;
	reversePtr = new item;
	
}



quack::~quack(void)
{
	delete frontPtr;
	delete backPtr;
	delete reversePtr;
	delete [] items;    // causing crash - i have also tried delete items;
   

}
I will attach the error
mrsirpoopsalot is offline   Reply With Quote
Old 10-26-2009, 03:56 PM   #2
Registered User
 
Join Date: Sep 2006
Location: vancouver wa
Posts: 216
Some reason i didnt notice that it didnt upload..
Attached Files
File Type: doc Doc2.doc (135.0 KB, 11 views)
mrsirpoopsalot is offline   Reply With Quote
Old 10-26-2009, 03:59 PM   #3
Registered User
 
Join Date: Sep 2006
Location: vancouver wa
Posts: 216
nevermind i foud the problem maxsize(capacity+1)
Sorry
mrsirpoopsalot is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quantum Random Bit Generator shawnt C++ Programming 62 06-18-2008 10:17 AM
Making C DLL using MSVC++ 2005 chico1st C Programming 26 05-28-2008 01:17 PM
Post... maxorator C++ Programming 12 10-11-2005 08:39 AM
Why wont my function exit correctly? LightsOut06 C Programming 2 10-09-2005 09:23 PM
Please Help - Problem with Compilers toonlover C++ Programming 5 07-23-2005 10:03 AM


All times are GMT -6. The time now is 01:12 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22