 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
sharat Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: error in compiling c++ program. |
|
|
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. |
|
| Back to top |
|
 |
sunderjs Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: Re: error in compiling c++ program. |
|
|
Code presented here seems incomplete. I don't see any line:54.
Copy the full code again !!
sharat wrote:
| Quote: | 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. |
|
|
| Back to top |
|
 |
David Harmon Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: Re: error in compiling c++ program. |
|
|
On 12 Oct 2006 22:55:24 -0700 in comp.lang.c++, "sharat"
<aaliya.zarrin (AT) gmail (DOT) com> wrote,
| Quote: | # 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* |
|
| Back to top |
|
 |
Kai-Uwe Bux Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: Re: error in compiling c++ program. |
|
|
sharat wrote:
| Quote: | 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)
| Quote: | {
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 |
|
| Back to top |
|
 |
Amol Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: Re: error in compiling c++ program. |
|
|
sharat wrote:
| Quote: | 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:
| Quote: |
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) {}
| Quote: | } *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. |
|
| Back to top |
|
 |
Salt_Peter Guest
|
Posted: Fri Oct 13, 2006 9:10 am Post subject: Re: error in compiling c++ program. |
|
|
sharat wrote:
| Quote: | 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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|