hi guys,
the error is as follows:
error C2440: '=' : cannot convert from 'TreeNode<T> *' to 'char *'
with
1> [
1> T=char
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
i get this error from the following line of code:
which is part of the following method
the searchTree method is below
could you please help me with this?
i will reply within 5 mins so plz do check back if u require anything else e.g. code or a qn answered.
thanks :)
i have included the TreeNode file below just in case:
the error is as follows:
error C2440: '=' : cannot convert from 'TreeNode<T> *' to 'char *'
with
1> [
1> T=char
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
i get this error from the following line of code:
Code:
assign = searchTree(treeObj->root ,data1);
Code:
void handleOneLine(string string1) { char * cstr, *p, *assign; int counter; string str (string1); char data1, data2, data3; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); // cstr now contains a c-string copy of str int count = 0; p=strtok (cstr,","); count++; while (p!=NULL) { p=strtok(NULL,","); if( count == 1 ) { data1 = *p; assign = searchTree(treeObj->root ,data1); treeNodeObj->item = new TreeNode(); } else if( count == 2 ) { data2 = *p; // treeNodeObj->setLeft(data2); } else if( count == 3 ) { data3 = *p; // treeNodeObj->setRight(data3); } count++; if( count == 3 ) break; } delete[] cstr; }
Code:
#include <iostream> #include <fstream> #include <string> #include <queue> #include <deque> #include "TreeNode.h" #include "Tree.h" using namespace std; Tree<char> *treeObj = NULL; TreeNode<char> *treeNodeObj = NULL; TreeNode<char>* searchTree(TreeNode<char> *cur, char nodeToAdd) { if(cur == NULL) { return NULL; } if(cur->IsSameNode(nodeToAdd)) { return cur; } searchTree(cur->getLeft(), nodeToAdd); searchTree(cur->getRight(), nodeToAdd); }
i will reply within 5 mins so plz do check back if u require anything else e.g. code or a qn answered.
thanks :)
i have included the TreeNode file below just in case:
Code:
#pragma once #include <iostream> #include <fstream> #include <string> #include <deque> #include <queue> using namespace std; template <class T> class TreeNode { public: TreeNode<T>(T newItem); ~TreeNode<T>(void); void setItem(T *newItem); void setLeft(TreeNode *newLeft); void setRight(TreeNode *newRight); T getItem(); TreeNode<T>* getLeft(); TreeNode<T>* getRight(); bool IsSameNode(T c); T item; private: TreeNode *left; TreeNode *right; }; template <class T> TreeNode<T>::TreeNode(T newItem) { item = newItem; left = null; right = null; } template <class T> TreeNode<T>::~TreeNode(void) { } template <class T> void TreeNode<T>::setItem(T *newItem) { // set methods item = newItem; } template <class T> void TreeNode<T>::setLeft(TreeNode *newLeft) { left = newLeft; } template <class T> void TreeNode<T>::setRight(TreeNode *newRight) { right = newRight; } template <class T> T TreeNode<T>::getItem() { // get methods return item; } template <class T> TreeNode<T>* TreeNode<T>::getLeft() { return left; } template <class T> TreeNode<T>* TreeNode<T>::getRight() { return right; } template <class T> bool TreeNode<T>::IsSameNode(T c) { return this->item == c; }
Comment