Connecting Tech Pros Worldwide Forums | Help | Site Map

error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'

Member
 
Join Date: Jul 2008
Posts: 34
#1: Sep 5 '08
well the error i get is the title above:
error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'

error is form this line
Expand|Select|Wrap|Line Numbers
  1. searchTree(treeObj->root ,data1.c_str());
  2.  
i have also attached searchTree below for yr reference
Expand|Select|Wrap|Line Numbers
  1. Tree<char> *treeObj = NULL;
  2. TreeNode<char> *treeNodeObj = NULL;
  3.  
  4. TreeNode<char>* searchTree(TreeNode<char> *cur, char nodeToAdd)
  5. {
  6.     if(cur == NULL) 
  7.     {
  8.         return NULL;
  9.     }
  10.     if(cur->IsSameNode(nodeToAdd))
  11.     {
  12.         return cur;
  13.     }
  14.     searchTree(cur->getLeft(), nodeToAdd);
  15.     searchTree(cur->getRight(), nodeToAdd);
  16. }
  17.  

could anyone help me with this problem..?
well at first i get the problem that it can convert from char to string.. thats y i added the .c_str() but now it gives me the new error above..
any help is appreciated..
I will check forum every 5 mins .. so i will reply quick..
Thanks in advance :)

Familiar Sight
 
Join Date: Oct 2006
Posts: 135
#2: Sep 5 '08

re: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'


what is 'data1' ? How did you declare it?

other than that, it LOOKS like you are attempting to make 'data1' into a string, and then pass it into a function looking for a char ... that's just not gonna happen ... why are you passing some sort of string into a char argument?
Member
 
Join Date: Jul 2008
Posts: 34
#3: Sep 5 '08

re: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'


oops my bad..
i declared it as string..

Expand|Select|Wrap|Line Numbers
  1. void handleOneLine(string string1)
  2. {
  3.     char * cstr, *p;
  4.     int counter;
  5.     string str (string1);
  6.     string data1, data2, data3;
  7.  
  8.     cstr = new char [str.size()+1];
  9.     strcpy (cstr, str.c_str());
  10.  
  11.     // cstr now contains a c-string copy of str
  12.  
  13.     int count = 0;
  14.     p=strtok (cstr,",");
  15.     count++;
  16.     while (p!=NULL)
  17.     {
  18.         p=strtok(NULL,",");
  19.         if( count == 1 )
  20.         {            
  21.             data1.append(p);
  22.             searchTree(treeObj->root ,data1.c_str());
  23.         }
  24.         else if( count == 2 )
  25.         {
  26.             data2.append(p);
  27. //            treeNodeObj->setLeft(data2);
  28.         }
  29.         else if( count == 3 )
  30.         {
  31.             data3.append(p);
  32. //            treeNodeObj->setRight(data3);
  33.         }
  34.         count++;
  35.         if( count == 3 )
  36.             break;
  37.     }
  38.  
  39.     delete[] cstr; 
  40. }
  41.  
Familiar Sight
 
Join Date: Oct 2006
Posts: 135
#4: Sep 5 '08

re: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'


I edited my previous post, not sure if you saw ...

it looks like you are attempting to make 'data1' into a string, and then pass it into a function looking for a char ... that's just not gonna happen ... why are you passing some sort of string into a char argument?
Member
 
Join Date: Jul 2008
Posts: 34
#5: Sep 5 '08

re: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'


Quote:

Originally Posted by manontheedge

I edited my previous post, not sure if you saw ...

it looks like you are attempting to make 'data1' into a string, and then pass it into a function looking for a char ... that's just not gonna happen ... why are you passing some sort of string into a char argument?


oh yea.. haha i must be looking like a fool now...
err... so just use char variables from the start then yea?
done that.. that problem is solved.

thanks for yr help :)
Familiar Sight
 
Join Date: Oct 2006
Posts: 135
#6: Sep 5 '08

re: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char'


it happens, everybody does that kind of stuff
Reply