Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error in compiling c++ program.

Reply
Thread Tools

error in compiling c++ program.

 
 
sharat
Guest
Posts: n/a
 
      10-13-2006
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.

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      10-13-2006
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


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      10-13-2006
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*

 
Reply With Quote
 
sunderjs
Guest
Posts: n/a
 
      10-13-2006
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.


 
Reply With Quote
 
Amol
Guest
Posts: n/a
 
      10-13-2006

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.

 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      10-13-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 09:47 PM
Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 08:55 PM
Problems with ld: Unresolved error C++ compiling error stevenruiz@gmail.com C++ 2 02-13-2007 09:04 PM
Problem with C++ Compiling Error ld: Unresolved Error stevenruiz@gmail.com C++ 2 02-13-2007 12:01 AM
Compiling when libedit is in path Is there a trick to compiling Ruby when libedit must exist in the search path? Can you statically link to readline 5.0 in some manner? -- Lon Baker Lon Baker Ruby 1 03-21-2005 08:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57