I am getting a segmentation fault when I try to dereference the pointer and call a simple member function. I don't understand though???
Is there a special syntax when dereferencing pointers to template classes or something?
heap.h
heap.cxxCode:namespace assignment5 { #include <iostream> #include <cstdlib> // Provides NULL and size_t using namespace std; template <class Item, class Key> class heapnode { public: heapnode(const Item& init_data = Item(), Key init_key = Key(), heapnode* init_left = NULL, heapnode* init_right = NULL, heapnode* init_parent = NULL) { data_field = init_data; key_field = init_key; left_child = init_left; right_child = init_right; parent_node = init_parent; } ~heapnode() { if(left_child) delete left_child; if(right_child) delete right_child; if(parent_node) delete parent_node; } Key getKey() { return key_field; } void setKey(Key temp) { key_field = temp; } Item getItem() { return data_field; } void setItem(Item temp) { data_field = temp; } heapnode* getLeft() { return left_child; } void setLeft(heapnode* temp) { left_child = temp; } heapnode* getRight() { return right_child; } void setRight(heapnode* temp) { right_child = temp; } heapnode* getParent() { return parent_node; } void setParent(heapnode* temp) { parent_node = temp; } bool isLeaf() const { if(parent_node && !left_child && !right_child) return true; else return false; } bool isRoot() const { if(!parent_node) return true; else return false; } private: Key key_field; Item data_field; heapnode* left_child; heapnode* right_child; heapnode* parent_node; }; template <class Process, class Item, class Key> void inorder_processing(heapnode<Item, Key> *root, Process f); template <class Process, class Item, class Key> void preorder_processing(heapnode<Item, Key> *root, Process f); template <class Process, class Item, class Key> void postorder_processing(heapnode<Item, Key> *root, Process f); template <class Item, class Key> bool check_node(heapnode<Item, Key>* root, Key k); template <class Item, class Key> void insert_node(heapnode<Item, Key>*& root, Key k, const Item& entry); template <class Item, class Key> void remove_node(heapnode<Item, Key>*& root, Key k); template <class Process, class Param, class Item, class Key> bool process_node(heapnode<Item, Key> *root, Key k, Process f, Param p); #include "heap.cxx" }
Code:#include <iostream> // Provides cin and cout #include <cstdlib> // Provides EXIT_SUCCESS #include "heap.h" using namespace std; using namespace assignment5; int main( ) { heapnode<int, int> *mydb = NULL; cout << mydb->getParent() << endl; return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks


