error in compiling c++ program.

Discussion in 'C++' started by sharat, Oct 13, 2006.

  1. sharat

    sharat Guest

    hi..

    In the following c++ program for tree(binary search .)
    while compiling i m getting the following error .

    program is :

    btree.cpp


    class btree
    {
    public:
    struct node
    {
    node *left;
    char data;
    node *right;
    } *root;

    char *arr;
    int *lc;
    int *rc;

    public:
    btree(char *a, int *l, int *r, int size);
    void insert(int index);
    static node* buildtree(char *a, int *l, int *r, int index);
    void display();
    static void inorder(node *sr);
    ~btree();
    static void del(node *sr);

    };



    node* btree :: buildtree(char *a, int *l, int *r, int index)
    {
    node *temp = NULL;
    if(index != -1)
    {
    temp = new node;
    temp->left = buildtree(a, l, r, *(l + index));
    temp->data = *(a + index);
    temp->right = buildtree(a, l, r, *(r + index));
    }

    return temp;
    }

    # g++ btree.cpp
    btree.cpp:54: error: expected constructor, destructor, or type
    conversion before '*' token.

    can any one plz help to sort it out.
    sharat, Oct 13, 2006
    #1
    1. Advertising

  2. sharat

    Kai-Uwe Bux Guest

    sharat wrote:

    > hi..
    >
    > In the following c++ program for tree(binary search .)
    > while compiling i m getting the following error .
    >
    > program is :
    >
    > btree.cpp
    >
    >
    > class btree
    > {
    > public:
    > struct node
    > {
    > node *left;
    > char data;
    > node *right;
    > } *root;
    >
    > char *arr;
    > int *lc;
    > int *rc;
    >
    > public:
    > btree(char *a, int *l, int *r, int size);
    > void insert(int index);
    > static node* buildtree(char *a, int *l, int *r, int index);
    > void display();
    > static void inorder(node *sr);
    > ~btree();
    > static void del(node *sr);
    >
    > };
    >
    >
    >
    > node* btree :: buildtree(char *a, int *l, int *r, int index)


    btree::node* btree :: buildtree(char *a, int *l, int *r, int index)

    > {
    > node *temp = NULL;
    > if(index != -1)
    > {
    > temp = new node;
    > temp->left = buildtree(a, l, r, *(l + index));
    > temp->data = *(a + index);
    > temp->right = buildtree(a, l, r, *(r + index));
    > }
    >
    > return temp;
    > }



    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Oct 13, 2006
    #2
    1. Advertising

  3. sharat

    David Harmon Guest

    On 12 Oct 2006 22:55:24 -0700 in comp.lang.c++, "sharat"
    <> wrote,
    ># g++ btree.cpp
    >btree.cpp:54: error: expected constructor, destructor, or type
    >conversion before '*' token.
    >
    >can any one plz help to sort it out.


    The compiler says the error is on line 54. There are less than 50
    lines in the fragment you posted. How can anybody help? Where is
    line 54?

    node* is unknown outside the context of class btree. Its name
    elsewhere is btree::node*
    David Harmon, Oct 13, 2006
    #3
  4. sharat

    sunderjs Guest

    Code presented here seems incomplete. I don't see any line:54.
    Copy the full code again !!

    sharat wrote:
    > hi..
    >
    > In the following c++ program for tree(binary search .)
    > while compiling i m getting the following error .
    >
    > program is :
    >
    > btree.cpp
    >
    >
    > class btree
    > {
    > public:
    > struct node
    > {
    > node *left;
    > char data;
    > node *right;
    > } *root;
    >
    > char *arr;
    > int *lc;
    > int *rc;
    >
    > public:
    > btree(char *a, int *l, int *r, int size);
    > void insert(int index);
    > static node* buildtree(char *a, int *l, int *r, int index);
    > void display();
    > static void inorder(node *sr);
    > ~btree();
    > static void del(node *sr);
    >
    > };
    >
    >
    >
    > node* btree :: buildtree(char *a, int *l, int *r, int index)
    > {
    > node *temp = NULL;
    > if(index != -1)
    > {
    > temp = new node;
    > temp->left = buildtree(a, l, r, *(l + index));
    > temp->data = *(a + index);
    > temp->right = buildtree(a, l, r, *(r + index));
    > }
    >
    > return temp;
    > }
    >
    > # g++ btree.cpp
    > btree.cpp:54: error: expected constructor, destructor, or type
    > conversion before '*' token.
    >
    > can any one plz help to sort it out.
    sunderjs, Oct 13, 2006
    #4
  5. sharat

    Amol Guest

    sharat wrote:
    > hi..
    >

    Why don't you provide constructor for the 'node'?
    and please provide the line number from where you are getting the
    error.
    Try this one:
    >
    > class btree {
    > struct node {
    > char data;
    > node *left;
    > node *right;

    node(char d = '\0',
    node* ll = 0, node* rr = 0) : data(d),

    left(ll), right(rr) {}
    > } *root;
    >
    > char *arr;
    > int *lc;
    > int *rc;
    >
    > public:
    > btree(char *a, int *l, int *r, int size);
    > void insert(int index);
    > static node* buildtree(char *a, int *l, int *r, int index);
    > void display();
    > static void inorder(node *sr);
    > ~btree();
    > static void del(node *sr);
    >
    > };
    >
    >
    >
    > node* btree::buildtree(const char *a, const int *l, const int *r, int index) {

    if (index != -1)
    > {
    > node* temp = new node(*(a + index));
    > temp->left = buildtree(a, l, r, *(l + index));
    > temp->right = buildtree(a, l, r, *(r + index));

    return temp;
    > }
    >
    > return 0;
    > }


    Well I hope this will provide some help to you.
    Amol, Oct 13, 2006
    #5
  6. sharat

    Salt_Peter Guest

    sharat wrote:
    > hi..
    >
    > In the following c++ program for tree(binary search .)
    > while compiling i m getting the following error .
    >
    > program is :
    >
    > btree.cpp
    >
    >
    > class btree
    > {
    > public:
    > struct node
    > {
    > node *left;
    > char data;
    > node *right;
    > } *root;
    >
    > char *arr;
    > int *lc;
    > int *rc;
    >
    > public:
    > btree(char *a, int *l, int *r, int size);
    > void insert(int index);
    > static node* buildtree(char *a, int *l, int *r, int index);
    > void display();
    > static void inorder(node *sr);
    > ~btree();
    > static void del(node *sr);
    >
    > };
    >
    >
    >
    > node* btree :: buildtree(char *a, int *l, int *r, int index)
    > {
    > node *temp = NULL;
    > if(index != -1)
    > {
    > temp = new node;
    > temp->left = buildtree(a, l, r, *(l + index));
    > temp->data = *(a + index);
    > temp->right = buildtree(a, l, r, *(r + index));
    > }
    >
    > return temp;
    > }
    >
    > # g++ btree.cpp
    > btree.cpp:54: error: expected constructor, destructor, or type
    > conversion before '*' token.
    >
    > can any one plz help to sort it out.


    a static member function can't access non-static members of a class. It
    can only access globals and static members.
    Salt_Peter, Oct 13, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    446
    Barry Schwarz
    Jun 2, 2006
  2. Ajinkya
    Replies:
    65
    Views:
    1,137
    Keith Thompson
    Oct 9, 2007
  3. Garrett Cooper
    Replies:
    0
    Views:
    535
    Garrett Cooper
    Feb 24, 2009
  4. Garrett Cooper
    Replies:
    0
    Views:
    475
    Garrett Cooper
    Feb 24, 2009
  5. Lon Baker
    Replies:
    1
    Views:
    205
    Csaba Henk
    Mar 21, 2005
Loading...

Share This Page