0

For an assignment, I'm to create a custom singly-linked list using a class previously created as the type.

When creating the node for the list in any methods in the custom list class, however, I get that my node type is unresolved. I have included the correct header file, and am in the correct name space. I am out of ideas as to why this is happening. Below is an example:

#include "RiderList.h"
#include "RiderNode.h"
using namespace cse274;

void RiderList::addToHead(Rider *el){
    head = new RiderNode(el,head); //this is where RiderNode is unresolved 
    if (tail == NULL)
       tail = head;
}

as requested...here are the two headers and the exact error:

#ifndef RIDERLIST_H_
#define RIDERLIST_H_

#include "RiderNode.h"

namespace cse274{
class RiderList{
public:
    RiderList() {
            head = tail = 0;
    }
    ~RiderList();

    bool isEmpty() {
        return head == 0;
    }
    void addToHead(Rider *ride);
    void addToTail(Rider *ride);
    Rider *deleteFromHead(); // delete the head and return its info;
    Rider  *deleteFromTail(); // delete the tail and return its info;

private:
    RiderList *head, *tail;
};
}
#endif /* RIDERLIST_H_ */

#ifndef RIDERNODE_H_
#define RIDERNODE_H_

#include "Rider.h"

namespace cse274{

class RiderNode{
public:
Rider *info;
RiderNode *next;

RiderNode(Rider *el, RiderNode *ptr) {
    info = el;
    next = ptr;
}
};

}
#endif /* RIDERNODE_H_ */

exact error message:

Type 'RiderNode' could not be resolved: name resolution problem found by the indexer

Any clues as to why this would occur? Thanks!

MSalters
  • 173,980
  • 10
  • 155
  • 350
user998385
  • 11
  • 1
  • 2
  • You should add the contents of `RiderList.h` and `RiderNode.h` to the question. – Mankarse Oct 17 '11 at 01:29
  • You should retag your question with a `homework` tag. And also show the exact error message from your compiler (at first sight, it seems like the linker is complaining about a missing symbol ...) – overcoder Oct 17 '11 at 01:30
  • It would be much easier to answer if you just stripped it down to only the code producing the error, make sure that it compiles cleanly and generates *only* that error and then paste in *all* of that code. – Ayjay Oct 17 '11 at 01:57
  • The code looks right to me. Did you try removing the 'using namespace cse274;' and directly referencing them as cse274::RiderNode ? – vishakvkt Oct 17 '11 at 02:47

2 Answers2

1

You have a misleading using namespace directive in your header files, so you should remove the lines stating using namespace cse274; on your headers and keep the namespace cse274 { ... }. Here is a question on SO about namespaces in header files with good responses.


EDIT : I found another problem I didn't saw the first time : You are calling a RiderNode(Rider *, RiderList *) constructor but you've only defined a RiderNode(Rider *, RiderNode *) constructor. Perhaps you should change the type of the members head and tail in RiderList from RiderList * to RiderNode * (it depends on your intended design of the RiderList, but in most cases a list is chain of nodes).

Community
  • 1
  • 1
overcoder
  • 1,523
  • 14
  • 24
  • I've fixed these, yet I'm still receiving the same error as before. – user998385 Oct 17 '11 at 02:15
  • You are reporting an error from the eclipse cdt indexer, but the error from the compiler will give more clues (you can find the full compiler output on the console tab of eclipse). – overcoder Oct 17 '11 at 02:43
  • That fixed it. I must've missed that when following a template for a linked list. Thanks a bunch. – user998385 Oct 17 '11 at 02:45
  • So now you should mark the question as resolved. And welcome to StackOverflow ! – overcoder Oct 17 '11 at 02:48
0
class RiderNode{
public:
Rider *info;
class RiderNode *next;

This looks like a problem, you don't need to use class twice in that definition. Specifying RiderNode *next; without the class should work. Try removing the second class and see what happens.

redache
  • 21
  • 2