Ok, I am having to do a child class call MyBinTree for a BinTree parent class. If you can't tell, this is dealing with binary trees. I am getting most of it, but here is an error I am running into. We are asked to write a function call genPreOrderArray, which will read the binary tree in the pre-order traversal. That function is supposed to return a pointer of whatever type is declared (we are using templates). Here is some code...
In the MyBinTree.h (Header file)
template <class obj>
MyBinTree<obj>* MyBinTree<obj>::genPreOrderArray()
{
return preOrder(root);
}
template <class obj>
MyBinTree<obj>* MyBinTree<obj>:: PreOrder(BinNodePtr nodePtr)
{
return nodePtr;
if(nodePtr->leftchild != NULL)
preOrder(nodePtr->leftchild);
if(nodePtr->rightchild != NULL)
preOrder(nodePtr->rightchild);
}
In the main.cpp which is making the calls
cout << "Pre Order : ";
char* treearray = mytree.genPreOrderArray();
for (int j=0;j<mytree.size();j++)
cout << treearray[j] << " ";
cout << endl << endl;
delete [] treearray;
My error generated is that is can't convert MyBinTree<char>* to char* and it refers to the char* treearray = mytree.genPreOrderArray(); line. I know I may have left out information you might need to answer this. So, please ask if you need more. I can't figure out how to fix this. Thanks.
[EDIT]
The reason I have the preOrder function as well as the genPreOrder Array is because the teacher said the genPreOrderArray couldn't take arguments, so this is the shortcut I used instead.
In the MyBinTree.h (Header file)
template <class obj>
MyBinTree<obj>* MyBinTree<obj>::genPreOrderArray()
{
return preOrder(root);
}
template <class obj>
MyBinTree<obj>* MyBinTree<obj>:: PreOrder(BinNodePtr nodePtr)
{
return nodePtr;
if(nodePtr->leftchild != NULL)
preOrder(nodePtr->leftchild);
if(nodePtr->rightchild != NULL)
preOrder(nodePtr->rightchild);
}
In the main.cpp which is making the calls
cout << "Pre Order : ";
char* treearray = mytree.genPreOrderArray();
for (int j=0;j<mytree.size();j++)
cout << treearray[j] << " ";
cout << endl << endl;
delete [] treearray;
My error generated is that is can't convert MyBinTree<char>* to char* and it refers to the char* treearray = mytree.genPreOrderArray(); line. I know I may have left out information you might need to answer this. So, please ask if you need more. I can't figure out how to fix this. Thanks.
[EDIT]
The reason I have the preOrder function as well as the genPreOrder Array is because the teacher said the genPreOrderArray couldn't take arguments, so this is the shortcut I used instead.
