Before I post, I want to note that I've been searching for 4 hours and tinkering with this and to no avail. I know it's a common question but please bare with me.
The important part of my code is below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
// The BST.h file
#ifndef BST_H
#define BST_H
#include <iostream>
#include "Object.h"
using namespace std;
class BST {
public:
BST(); // Default Constructor
BST(const BST &); // Copy-Constructor
~BST(); // Destructor
Node *copyHelper(const Node*); //The recursive helper
private:
struct Node {
Generic *item; //Another written class that's a generic item
Node *right;
Node *left;
};
Node *root;
};
#endif BST_H
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//The BST.cpp
#include "BST.h"
// Default Constructor
BST::BST(){
this->root = NULL;
}
// Copy-Constructor
BST::BST(const BST &toCopy){
root = copyHelper(toCopy.root);
}
// Destructor
BST::~BST(){
this->makeEmpty(); // A working method I left out for readability
}
//Helper Method
BST::Node* BST::copyHelper(const Node *toCopy){
if (toCopy == NULL)
return NULL;
Node *copyNode = new Node;
copyNode->item = toCopy->item;
copyNode->ticker = toCopy->ticker;
copyNode->left = copyHelper(toCopy->left);
copyNode->right = copyHelper(toCopy->right);
return copyNode;
}
//End cpp
|
In my main, I call something to this effect:
1 2 3
|
BST treeA, treeB;
constructBST(infile, treeA); //A helper to build BST from file
BST copyCat(treeA);
|
Everything is fine and good, it compiles, it runs, even copies and passes an equal test, but then come the error messages.
I'm using MS Visual Studio 2010, and the window pops up and says
Microsoft Visual C++ Debug Library
Debug Assertion Failed!
Program: ...visual studio
2010\Projects\Muski_CS_BST\Debug\Muski_CS_BST.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgdel.cpp
Line:52
Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information on how your program can cause assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
--Then it gives me abort, retry or ignore options. Retry just crashes it, abort crashes it, and ignore sens another message the same type, but the expression line is:
Expression:_CrtIsValidHeapPointer(pUserData)
Then if I hit ignore again it shows the original message and then crashes.
I am so beyond lost after days of tearing my hair out over this. I know the logic is right and I could write it without recursion easily but we're here to learn :)
Any help at all would be GREATLY appreciated! Thanks so much!