Thread: Binary Tree 911

  1. #1
    Registered User
    Join Date
    Apr 2003

    Binary Tree 911

    Hi all I'm so close to getting this stupid binary tree to work except I keep getting some wack ass error message. It says
    and I quote error C2440: '=' : cannot convert from 'char' to 'char12]'
    observe the code
    #include <iostream>
    #include <string>
    using namespace std;
    struct node
        char info[12];
        node *left;
        node *right;
    								//The line below should be in main and you should probably
    								//not be allocating memory for a new node at this point,
    								//that will be done in the insert function, you
    								//should just set it to NULL in main
    								// Forgot to add the return types for the two functions below
    void preorder(node *p);
    void inorder(node *p);		    //is this the correct syntax for declaring the function?
    void insert(node *&p, char string[12]);   //for user defined functions using pointers?
    void insert(node *&p, char string[12])    // This differs from the function prototype you provided above
            p->info = string[12];   
        else if(string < p->info) 
            insert(p->left,  string);
        else   insert(p->right, string);
    }  // You were missing an ending bracket, add this
    void inorder(node *p)
            cout<<p->info<<"  ";
    void preorder(node *p)
    		cout<<p->info<<"  ";
    		preorder( p->left);
    int main() // main should always return an int
        node *root=NULL;
    	char string[12];
    	for(int i=0; i<6; ++i)
    		cout<<"Enter the value for your node: ";
    		 cin.getline(string, 11, '\n');
    		insert(root, string[12]); // Your insert function takes two parameters but you only provide one
    	return 0;
    anyhow could anyone out there give me some feedback on where I'm going wrong here.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > insert(root, string[12]); // Your insert function
    To pass an array to a function, you just write it's name

    insert(root, string);

    > error C2440: '=' : cannot convert from 'char' to 'char12]'
    Well yes, because string[12] is an element of the array (a char), and string is the array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM