error in compiling c++ program.

S

sharat

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.
 
K

Kai-Uwe Bux

sharat said:
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
 
D

David Harmon

On 12 Oct 2006 22:55:24 -0700 in comp.lang.c++, "sharat"
# 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*
 
S

sunderjs

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

Amol

sharat said:
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.
 
S

Salt_Peter

sharat said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top