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

K

Kabeer

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.
 
V

Victor Bazarov

Kabeer said:
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
 
K

Kabeer

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.
 
K

Kabeer

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 ..?
 
E

ES Kim

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.
 
C

Christian Janßen

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
 
T

Thomas Matthews

Kabeer said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top