The first problem is this: I want to create a LinkedList of type_A. type_A will contain a LinkedList of type_B. The below code fails at compile saying: Node_B does not name a type.

The only way i see around this is to create different LinkList.cpp files for each type (such as LL_TypeA.cpp, LL_TypeB.cpp). Then, I could include the LL_TypeB class in the LL_TypeA.cpp file, and instantiate a new variable of LL_TypeB inside a node of Type_A. This seems wasteful. I believe I should have one LinkList.cpp which has the basic code needed to link to a new node of any type. Then i could typecast the node i am creating and link it.

I've tried creating nested classes inside the linkedlist class: class linklist{class Type_A{} class Type_B{}} with Type_A/B having it's own struct's for their "nodes".. but i don't know how to reference a struct within nested classes. if i could do this, then maybe i could create a dummy class and a dummynode and then in the cpp file typecast the class and then create a new node and typecast that to be either Type_A or Type_B.. could that work?

Is there a better way?

#ifndef __LINKEDLIST_H
#define __LINKEDLIST_H
#include <string>

using namespace std;

class linklist
{
     private:

     struct Node_A
         {
              string data;
             Node_A *link;
             Node_B myNode_B
         }*A;

     struct Node_B
         {
             string data;
             Node_B *link;
         }*B;
}

Line 15 fails because Node_B has not been declared yet. Reverse the order of Node_A and Node_B and it should compile.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.