By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Error creating a node

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a

"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

P: n/a
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

P: n/a
>
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.