Ethan
Ethan

Reputation: 1266

Including a class in another class

So I'm trying to use the Node class that I just wrote in my LinkedList class but I'm getting the error that:

Symbol 'Node' could not be resolved

in the code below.

#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_

#include "Node.h"

template<class T>
class LinkedList {

    private:
        //Data Fields-----------------//
        Node<T> head;
        Node<T> tail;
};

#endif /* LINKEDLIST_H_ */

Node's declaration is below:

#ifndef NODE_H_
#define NODE_H_

template<class T>
class Node {

UPDATE:

So I still am having issues with my Node class being included in my LinkedList. But I discovered that by placing the two classes in one header file, I have no problems. So it must mean that the problem lies solely with the inclusion....which confuses me because that makes it seem like its some language based nuance that a beginner to C++ like me doesn't know about..

Upvotes: 0

Views: 295

Answers (2)

Ujjwal Singh
Ujjwal Singh

Reputation: 4988

why do you have the semicolon after #include "Node.h" that's the problem.
Edit: Things you can do to troubleshoot:

  1. Inline the class definition
    i.e. replace the # include statement with the actual definition of the class (for testing only)
  2. Check your header guards (the ones like # ifndef LINKEDLIST_H_
    try renaming them or removing them altogether (again for testing only)

Upvotes: 2

Ethan
Ethan

Reputation: 1266

So this just randomly started working for me...I don't know what the problem was but it works now... I'm using the CDT with eclipse, and it isn't the most stable thing for C++ development. SO my guess is that it has to do with that somehow....

Upvotes: 0

Related Questions