By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,796 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,796 IT Pros & Developers. It's quick & easy.

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

P: 34
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 :)
Sep 5 '08 #1
Share this Question
Share on Google+
5 Replies


100+
P: 175
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?
Sep 5 '08 #2

P: 34
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.  
Sep 5 '08 #3

100+
P: 175
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?
Sep 5 '08 #4

P: 34
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 :)
Sep 5 '08 #5

100+
P: 175
it happens, everybody does that kind of stuff
Sep 5 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.