C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

error in compiling c++ program.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
sharat
Guest





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: error in compiling c++ program. Reply with 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
sunderjs
Guest





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: Re: error in compiling c++ program. Reply with quote



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





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: Re: error in compiling c++ program. Reply with quote



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





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: Re: error in compiling c++ program. Reply with quote

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





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: Re: error in compiling c++ program. Reply with quote

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





PostPosted: Fri Oct 13, 2006 9:10 am    Post subject: Re: error in compiling c++ program. Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.