Thread: Heap corruption Detected Error

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    vancouver wa
    Posts
    221

    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

  2. #2
    Registered User
    Join Date
    Sep 2006
    Location
    vancouver wa
    Posts
    221
    Some reason i didnt notice that it didnt upload..

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    vancouver wa
    Posts
    221
    nevermind i foud the problem maxsize(capacity+1)
    Sorry

Popular pages Recent additions subscribe to a feed

Similar Threads

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