473,401 Members | 2,068 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,401 software developers and data experts.

Error creating a node

I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get
an error saying "error C2629: unexpected 'Node ('" which is on the line for
the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?
Thanks
Allan
#include <iostream>

class Node
{
public:
Node();
Node(char xiType);
virtual ~Node();

void SetNextLink(Node *xiNode){NextNode = xiNode);
void SetPrevLink(Node *xiNode){PrevNode = xiNode);
Node *GetPrevLink(){return PrevNode;}
Node *GetNextLink(){return NextNode;}
void SetData(void *xiData){Data = xiData;}
void *GetData(){return Data;}
private:
Node *NextNode;
Node *PrevNode;
void *Data;
bool Tail;
bool Head;
};

Jul 22 '05 #1
11 2275

"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message news:br**********@news.freedom2surf.net...
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get
an error saying "error C2629: unexpected 'Node ('" which is on the line for
the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?


Are you sure the previous line really has a semicolon at the end of it?

Jul 22 '05 #2

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f*********************@news.newshosting.com. ..

"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message

news:br**********@news.freedom2surf.net...
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get an error saying "error C2629: unexpected 'Node ('" which is on the line for the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?


Are you sure the previous line really has a semicolon at the end of it?


There are no other classes before this one, but they do all have semi-colons
at the end of the class definitions.
Allan
Jul 22 '05 #3
Allan Bruce wrote:
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f*********************@news.newshosting.com. ..
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message


news:br**********@news.freedom2surf.net...
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I
get
an error saying "error C2629: unexpected 'Node ('" which is on the line
for
the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?


Are you sure the previous line really has a semicolon at the end of it?

There are no other classes before this one, but they do all have semi-colons
at the end of the class definitions.
Allan


No, Ron meant are you absolutely sure that you have a semicolon after the default constructor, and not a colon?
i.e. did you retype, or did you cut&paste?
Jul 22 '05 #4

"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:br**********@news.freedom2surf.net...
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get an error saying "error C2629: unexpected 'Node ('" which is on the line for the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?
Thanks
Allan
#include <iostream>

class Node
{
public:
Node();
Node(char xiType);
virtual ~Node();

void SetNextLink(Node *xiNode){NextNode = xiNode);
void SetPrevLink(Node *xiNode){PrevNode = xiNode);
Node *GetPrevLink(){return PrevNode;}
Node *GetNextLink(){return NextNode;}
void SetData(void *xiData){Data = xiData;}
void *GetData(){return Data;}
private:
Node *NextNode;
Node *PrevNode;
void *Data;
bool Tail;
bool Head;
};


I think the problem is in my methods, as I am trying to return a pointer to
a class called Node, but during the definition of Node itself - how do I
this in C++?
Thanks
Allan
Jul 22 '05 #5
Allan Bruce wrote:
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get
an error saying "error C2629: unexpected 'Node ('" which is on the line for
the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?
Thanks
Allan
#include <iostream>

class Node
{
public:
Node();
Node(char xiType);
virtual ~Node();

void SetNextLink(Node *xiNode){NextNode = xiNode); '{NextNode = xiNode);'

should be: '{NextNode = xiNode;}'

Note that you've paired a right paren to a left curly brace. Also,
you've put the semicolon after the right paren, when it should be at the
end of the statement.
void SetPrevLink(Node *xiNode){PrevNode = xiNode);
Same mistakes on this line.
Node *GetPrevLink(){return PrevNode;}
Node *GetNextLink(){return NextNode;}
void SetData(void *xiData){Data = xiData;}
void *GetData(){return Data;}
private:
Node *NextNode;
Node *PrevNode;
void *Data;
bool Tail;
bool Head;
};


The rest is fine, although I'm not crazy about the pointers to void. I
suspect that either you or your mentor is a refugee from C. ;-)

Seriously, pointers to void are usually not appropriate in C++ code,
unless you need to interface with existing code written in C.

- Adam

--
Reverse domain name to reply.

Jul 22 '05 #6

"red floyd" <no*****@here.dude> wrote in message
news:AN*******************@newssvr29.news.prodigy. com...
Allan Bruce wrote:
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f*********************@news.newshosting.com. ..
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:br**********@news.freedom2surf.net...
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I


get
an error saying "error C2629: unexpected 'Node ('" which is on the line


for
the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?

Are you sure the previous line really has a semicolon at the end of it?

There are no other classes before this one, but they do all have semi-colons at the end of the class definitions.
Allan


No, Ron meant are you absolutely sure that you have a semicolon after the

default constructor, and not a colon? i.e. did you retype, or did you cut&paste?

I did cut and paste but missed out the inline constructors. I found that
there was an error there as I was using a type BYTE without including the
necessary header.
My main problem is in the fact that I want to return a pointer to a class
that I am defining, if you know what I mean.
Allan
Jul 22 '05 #7

"Adam Fineman" <af******@retupmoc.org> wrote in message
news:%O*****************@news.uswest.net...
Allan Bruce wrote:
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get an error saying "error C2629: unexpected 'Node ('" which is on the line for the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?
Thanks
Allan
#include <iostream>

class Node
{
public:
Node();
Node(char xiType);
virtual ~Node();

void SetNextLink(Node *xiNode){NextNode = xiNode);

'{NextNode = xiNode);'

should be: '{NextNode = xiNode;}'

Note that you've paired a right paren to a left curly brace. Also,
you've put the semicolon after the right paren, when it should be at the
end of the statement.
void SetPrevLink(Node *xiNode){PrevNode = xiNode);


Same mistakes on this line.
Node *GetPrevLink(){return PrevNode;}
Node *GetNextLink(){return NextNode;}
void SetData(void *xiData){Data = xiData;}
void *GetData(){return Data;}
private:
Node *NextNode;
Node *PrevNode;
void *Data;
bool Tail;
bool Head;
};


The rest is fine, although I'm not crazy about the pointers to void. I
suspect that either you or your mentor is a refugee from C. ;-)

Seriously, pointers to void are usually not appropriate in C++ code,
unless you need to interface with existing code written in C.


Thanks.
I have originally came from a C background hence the void pointers. What
would be the best way to implement this in C++?
Also, I have a problem with the code in my methods, as I am returning a Node
* during the defintion of class Node. My compiler doesnt like it. I guess
it is similar to C where I would have to use 'struct Node *' whilst in the
definition of the struct, but I dont know how to do it for classes.
Allan
Jul 22 '05 #8

"Adam Fineman" <af******@retupmoc.org> wrote in message
news:%O*****************@news.uswest.net...
Allan Bruce wrote:
I am making my own linked list implementation just to get some basic
knowledge of slightly more advanced C++. I have the class below, but I get an error saying "error C2629: unexpected 'Node ('" which is on the line for the overlaoded constructor Node(char xiType)
Can anybody tell me where I am going wrong?
Thanks
Allan
#include <iostream>

class Node
{
public:
Node();
Node(char xiType);
virtual ~Node();

void SetNextLink(Node *xiNode){NextNode = xiNode);

'{NextNode = xiNode);'

should be: '{NextNode = xiNode;}'

Note that you've paired a right paren to a left curly brace. Also,
you've put the semicolon after the right paren, when it should be at the
end of the statement.
void SetPrevLink(Node *xiNode){PrevNode = xiNode);


Same mistakes on this line.
Node *GetPrevLink(){return PrevNode;}
Node *GetNextLink(){return NextNode;}
void SetData(void *xiData){Data = xiData;}
void *GetData(){return Data;}
private:
Node *NextNode;
Node *PrevNode;
void *Data;
bool Tail;
bool Head;
};


The rest is fine, although I'm not crazy about the pointers to void. I
suspect that either you or your mentor is a refugee from C. ;-)

Seriously, pointers to void are usually not appropriate in C++ code,
unless you need to interface with existing code written in C.


Thanks.
I have originally came from a C background hence the void pointers. What
would be the best way to implement this in C++?
Allan

Jul 22 '05 #9
Allan Bruce wrote:
"Adam Fineman" <af******@retupmoc.org> wrote in message
news:%O*****************@news.uswest.net...
Allan Bruce wrote:
<snip>
void *Data;
<snip>Seriously, pointers to void are usually not appropriate in C++ code,
unless you need to interface with existing code written in C.

Thanks.
I have originally came from a C background hence the void pointers. What
would be the best way to implement this in C++?
Allan


If you're making a truely generic container, then you should use a template:

template<typename data_t>
class my_list
{
// ...

private:
data_t* d_data;
// ...
};

There are, of course, many alternatives. You could use some type of
smart pointer to data_t instead of a native pointer.

The template lets you store any type in this container. If you know
beforehand what types will be stored, you may opt to represent data_t as
a class or hierarchy of classes.

The advantage of these approaches over using void* is that you have some
type safety.

You should check out the FAQ for this newsgroup for some good ideas:
http://www.parashift.com/c++-faq-lite/

Also, you could check out the book reviews at http://www.accu.org/.

HTH,

Adam

--
Reverse domain name to reply.

Jul 22 '05 #10
>
If you're making a truely generic container, then you should use a template:
template<typename data_t>
class my_list
{
// ...

private:
data_t* d_data;
// ...
};

There are, of course, many alternatives. You could use some type of
smart pointer to data_t instead of a native pointer.

The template lets you store any type in this container. If you know
beforehand what types will be stored, you may opt to represent data_t as
a class or hierarchy of classes.

The advantage of these approaches over using void* is that you have some
type safety.

You should check out the FAQ for this newsgroup for some good ideas:
http://www.parashift.com/c++-faq-lite/

Also, you could check out the book reviews at http://www.accu.org/.

HTH,

Adam


Thanks, I have had a look at the FAQ, but I am still having trouble with the
argument list. I posted the problems about it in a post subject "Using
Class Templates". I have another question though. Am I correct in thinking
I have to specify in the argument list, all types I wish to store in my
list? If so, is this not rather restricitve? I mean, if I want to store a
type of a specific class, I would have to add this class to the argument
list?
Thanks
Allan
Jul 22 '05 #11
Allan Bruce wrote:
<snip>
I have another question though. Am I correct in thinking
I have to specify in the argument list, all types I wish to store in my
list? If so, is this not rather restricitve? I mean, if I want to store a
type of a specific class, I would have to add this class to the argument
list?


I'm not sure what you mean by "argument list." Class templates have to
be specialized when you create an object of that class. If you want
examples of this, have a look at std::list, std::vector, etc. For example:

std::list<int> loi;
loi.push_back(1);
loi.push_back(2);

class some_type { /* ... */ };

std::vector<some_type> lost;
some_type st(/* ... */);
lost.push_back(st);

etc.

Have a look at some good C++ standard library documentation for more
information.

- Adam

--
Reverse domain name to reply.

Jul 22 '05 #12

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

Similar topics

7
by: Yngve | last post by:
Hi! I am trying to make two pointers at instances of the same class wich is beeing defined. But i get the following error from the compiler (MVC7): -------------------- ...
5
by: cayblood | last post by:
Hello, I have a vector of pointers to a class, like so: vector<Node*> m_parents; I'm having trouble creating an iterator to go through the elements in this vector. Here is my syntax: ...
4
by: Filippo Pandiani | last post by:
SCENARIO ======================================= I have a Grid and I want to save the values on an XML. Let me say that I am NOT using DataSet to load valus on my grid. PROBLEM...
3
by: Robert Kane | last post by:
Good afternoon, I'm trying to set up a clustered DB2 v7.1 database on Redhat Linux 7.3. I've followed the instructions (as far as I know) in the accompanying documentation to set up the database...
0
by: DB2 newsgroup user | last post by:
we need help with the following error. The system is a SUSE Enterprise Server: Linux db2serv 2.4.19-64GB-SMP #1 SMP Thu Mar 20 14:41:55 UTC 2003 i686 unknown Installed is DB2 Workgroup Edition...
5
by: NG | last post by:
Hi, We are having DB2-V7.2 DB on AIX 5.2 machine. Recently we upgraded our system to fixpack 13 and activated activate AIX asynchronous IO function. Our DB is going to crash recovery with...
4
by: PRadyut | last post by:
hi, i have written a function in adding a node to the linked list but this only adds "1" to the list as i get in the output I'm using borland c++ compiler The code...
5
by: Pucca | last post by:
I'm gettting this error at "Application.Run" in the code below. The error message also says "Out of Memory". How can I find out more about what's causing this error? It just breaks there with no...
0
by: Bhavesh D | last post by:
Hi Expert, I am facing below error while creating PO in 'Great plains' system via econnect layer. Actually we are exporting PO data from our system to Great plains vie econnect. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.