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

Discussion in 'C++' started by Kabeer, Aug 21, 2003.

  1. Kabeer

    Kabeer Guest

    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.
    Kabeer, Aug 21, 2003
    #1
    1. Advertising

  2. "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...?


    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
    Victor Bazarov, Aug 21, 2003
    #2
    1. Advertising

  3. Kabeer

    Kabeer Guest

    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.
    Kabeer, Aug 21, 2003
    #3
  4. Kabeer

    Kabeer Guest

    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 ..?
    Kabeer, Aug 21, 2003
    #4
  5. Kabeer

    ES Kim Guest

    "Kabeer" <> wrote in message
    news:bi20rs$...

    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
    ES Kim, Aug 21, 2003
    #5
  6. > 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
    Christian Janßen, Aug 21, 2003
    #6
  7. 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
    Thomas Matthews, Aug 21, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,412
  2. Rahul T.
    Replies:
    3
    Views:
    8,679
    sundar
    Dec 3, 2004
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,404
    Dimitre Novatchev
    Aug 24, 2006
  4. uche
    Replies:
    4
    Views:
    894
    Lionel B
    Feb 18, 2007
  5. Travis
    Replies:
    6
    Views:
    534
    Markus Schoder
    Jun 28, 2007
Loading...

Share This Page