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

'NODE' is used as a type, but has not been defined as a type

P: n/a
Hi All,

In my .h file I give definition as

typedef struct node {
struct node *next; /* Points at the next node in the
list */
struct node *previous; /* Points at the previous node in
the list */
}NODE;

but when I use it in my .C the compiler says

NODE * LLClass::lstFirst (MyLIST *myList)
{
return(myList->node.next);
}

Error 419: line 368 # 'NODE' is used as a type, but has not been defined as
a type.

I am not able to judge where the code is wrong

Anyone have any clue...?

Thanks in Advance,
Vijay.
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Kabeer" <vi********@excite.com> wrote...
Hi All,

In my .h file I give definition as

typedef struct node {
struct node *next; /* Points at the next node in the
list */
struct node *previous; /* Points at the previous node in
the list */
}NODE;

but when I use it in my .C the compiler says

NODE * LLClass::lstFirst (MyLIST *myList)
{
return(myList->node.next);
}

Error 419: line 368 # 'NODE' is used as a type, but has not been defined as a type.

I am not able to judge where the code is wrong

Anyone have any clue...?


Since you're not posting the real code, just bits and pieces of it,
here is one guess: did you actually include the .h file in your .C
file, or did you forget?

Also, another clue: types are better defined in a C++ way:

struct NODE {
blah
};

Victor
Jul 19 '05 #2

P: n/a
It is not all that the .h is not picked. It is being picked up.

The details needed are :

I need a linked list in my C++ program.. so I am creating a node for the
same with the definition:

typedef struct node
{
struct node *next;
struct node *previous;
} NODE;

while using this in my .C, i have function returning me a NODE *
NODE * myclass::GetFirst(MyList *list)
{
return the NODE after search...
}

When I compile I get an error
Error 419: "~user/MyClass.C", line 409 # 'NODE' is used as a type, but has
not been defined as a type.
NODE* MyClass::GetFirst (MyList *list)
^^^^

Thanks in Advance.
Jul 19 '05 #3

P: n/a

MyList.h
ALL THE INCLUDES....
..
..
..
class LinkedListClass:
{

public:
LinkedListClass();
~LinkedListClass();

typedef struct node {
struct node *next; /* Points at the next node in the
list */
struct node *previous; /* Points at the previous node in
the list */
} LNODE;

typedef struct{ /* Header for a linked list. */
LNODE node; /* Header list node */
int count; /* Number of nodes in list */
} MyList;

private:

MyLIST winlist;
LNODE* lstLast (MyLIST *pList);

};

MyList.C

ALL INCLUDES...
LinkedListClass::LinkedListClass()
{

}

LinkedListClass::~LinkedListClass()
{

}
NODE *LinkedListClass::lstLast (MyLIST *pList)
{
return(pList->node.previous);
}
NOW when I compile the .C the error say that the NODE is not defined as type
but is used as type... do I have to use it by LinkedListClass::NODE ..?
Jul 19 '05 #4

P: n/a
"Kabeer" <vi********@excite.com> wrote in message
news:bi********@netnews.proxy.lucent.com...

It should've been much easier if you had posted a minimal and
complete code. *sigh*

MyList.h
ALL THE INCLUDES....
.
.
.
class LinkedListClass:
class LinkedListClass // no colon
{

public:
LinkedListClass();
~LinkedListClass();

typedef struct node {
struct node *next;
struct node *previous;
} LNODE;

typedef struct{
LNODE node;
int count;
} MyList;
MyLIST, not MyList

private:

MyLIST winlist;
LNODE* lstLast (MyLIST *pList);

};

MyList.C

ALL INCLUDES...
LinkedListClass::LinkedListClass()
{

}

LinkedListClass::~LinkedListClass()
{

}
NODE *LinkedListClass::lstLast (MyLIST *pList)
LinkedListClass::LNODE *LinkedListClass::lstLast (MyLIST *pList)
{
return(pList->node.previous);
}
NOW when I compile the .C the error say that the NODE is not defined as type
but is used as type... do I have to use it by LinkedListClass::NODE ..?


Another point: Refer to Mr. Bazarov's comment on the declaration of
a struct.

--
ES Kim
Jul 19 '05 #5

P: n/a
> class LinkedListClass:
{

public:
LinkedListClass();
~LinkedListClass();

typedef struct node {
struct node *next; /* Points at the next node in the
list */
struct node *previous; /* Points at the previous node in
the list */
} LNODE;
NODE or LNODE. You wrote NODE in all your prior postings.
typedef struct{ /* Header for a linked list. */
LNODE node; /* Header list node */
int count; /* Number of nodes in list */
} MyList;

private:

MyLIST winlist;
LNODE* lstLast (MyLIST *pList);

}; NODE *LinkedListClass::lstLast (MyLIST *pList)
Should be
LinkedListClass::LNODE* ...
{
return(pList->node.previous);
}


Christian
Jul 19 '05 #6

P: n/a
Kabeer wrote:
Hi All,

In my .h file I give definition as

typedef struct node {
struct node *next; /* Points at the next node in the
list */
struct node *previous; /* Points at the previous node in
the list */
}NODE;

but when I use it in my .C the compiler says

NODE * LLClass::lstFirst (MyLIST *myList)
{
return(myList->node.next);
}

Error 419: line 368 # 'NODE' is used as a type, but has not been defined as
a type.

I am not able to judge where the code is wrong

Anyone have any clue...?

Thanks in Advance,
Vijay.


By the way, using the typedef is not required in C++.
You could just declare the struct:
// Forward declaration:
struct NODE;

struct NODE
{
NODE * next;
NODE * prev;
};

But, a link list usually has a data field associated with it:
template <class DataType>
struct DataNode
: public NODE
{
DataType data;
};
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.