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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slizorn
    New Member
    • Jul 2008
    • 34

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

    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
    Code:
    searchTree(treeObj->root ,data1.c_str());
    i have also attached searchTree below for yr reference
    Code:
    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);
    }

    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 :)
  • manontheedge
    New Member
    • Oct 2006
    • 175

    #2
    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?

    Comment

    • slizorn
      New Member
      • Jul 2008
      • 34

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

      Code:
      void handleOneLine(string string1)
      {
      	char * cstr, *p;
      	int counter;
      	string str (string1);
      	string 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.append(p);
      			searchTree(treeObj->root ,data1.c_str());
      		}
      		else if( count == 2 )
      		{
      			data2.append(p);
      //			treeNodeObj->setLeft(data2);
      		}
      		else if( count == 3 )
      		{
      			data3.append(p);
      //			treeNodeObj->setRight(data3);
      		}
      		count++;
      		if( count == 3 )
      			break;
      	}
      
      	delete[] cstr; 
      }

      Comment

      • manontheedge
        New Member
        • Oct 2006
        • 175

        #4
        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?

        Comment

        • slizorn
          New Member
          • Jul 2008
          • 34

          #5
          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 :)

          Comment

          • manontheedge
            New Member
            • Oct 2006
            • 175

            #6
            it happens, everybody does that kind of stuff

            Comment

            Working...