473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.

Oct 13 '06 #1
5 1555
On 12 Oct 2006 22:55:24 -0700 in comp.lang.c++, "sharat"
<aa***********@gmail.comwrote,
># 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*

Oct 13 '06 #2
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
Oct 13 '06 #3
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.
Oct 13 '06 #4

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.

Oct 13 '06 #5

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.

Oct 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: c++newbie | last post by:
Hi all, I try to compile the following classes: main.cpp: #include <algorithm> #include <iostream> #include <fstream> #include <iterator>
1
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed...
2
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project...
0
by: Herman Jones | last post by:
I'm getting the following error when I build a Class Library project: Embedding manifest... Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'. It happens with...
2
by: teddybyte | last post by:
my script below is: #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, ...
1
by: Toby | last post by:
Hi, I've managed to get my hands on the ms 2003 toolkit, and have successfully (i think) created a .pyd file in win xp (setup.py is provided intersystems cache): ...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
by: stevenruiz | last post by:
Hi Everyone, The Strings.h has the function Get_Line which is defined and the error is shown below: Strings.h: void get_line( istream & );
1
by: SQACPP | last post by:
I have an error when compiling a simple form project... I just start a new Form project and add a new PictureBox in a form(or anything that generate the .resx file) After that when compiling I...
0
by: dami.gupta | last post by:
I am building a chm file using sandcastle and am following instructions on https://blogs.msdn.com/sandcastle/archive/2006/07/29/682398.aspx I am following all the commands which are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.