c++ - How do I solve "[Error] invalid use of incomplete type 'class SLLNode'" Linked Lists -


hi i'm trying solve error getting when try pass linked list class have. have looked through other questions non of them seem fix problem.

i need sllnode stay in listassll because parent other classes

dynamicsizematrix supposed have aggregation listassll

my dynamicsizematrix.cpp file

#include "dynamicsizematrix.h" #include<iostream> #include<string> #include<cassert> #include<cstdlib> #include"listassll.h"  using namespace std;  dynamicsizematrix::dynamicsizematrix(sllnode* sll,int r, int *c) {      rws = r;     col = new int [rws];         for(int x=0; x < rws; x++) // sets different row sizes         {             col[x] = c[x];         }      sllnode *node = sll ; //  node = sll.head;      *info = new sllnode*[rws];     (int x= 0; x< rws;x++)     {         info[x] = new sllnode*[col[x]];      }      for(int x=0;x<rws;x++)     {         for(int y=0;y<col[x];y++)         {             info[x][y] = node;             node = node->next; // error happens here           }     }   } 

my "dynamicsizematrix.h"

#include"listassll.h"    #include "listasdll.h" #include"matrix.h" #include"object.h" class sllnode;  class dynamicsizematrix : public matrix {  private:     sllnode*** info;     //object* colmns;     int rws;     int *col; //array of column sizes     //  int size;  public:     dynamicsizematrix()     {         info = 0;         rws = 0;         col = 0;     }     dynamicsizematrix(sllnode* sll,int r, int *c); //...... 

and "listassll.h"

class listassll : public list {     //friend class lliterator;     friend class dynamicsizematrix;     protected:          struct sllnode         {                 object* info;                 sllnode* next;             //  sllnode(object *e, listassll::sllnode* ptr = 0);         };          sllnode* head;         sllnode* tail;         sllnode* cpos; //current postion;         int count;      public:              listassll();          ~listassll();         ////////////// 

thanks in advance

in class listassll, point of view of external class using it, has access public members. can see sllnode in protected section.

so have 2 options (well, there quite few), here 2 keep encapsulated in same file least:

  1. move sllnode declaration public section , use like: listassll::sllnode instead of sllnode.
  2. just move outside of class make accesable include "listassll.h".

i prefer method 1 since keeps scope smaller/more relevant, there not in really.... eg:

class listassll : public list {        public:         struct sllnode         {                 object* info;                 sllnode* next;         };         listassll();      protected:         sllnode* head;         sllnode* tail;         sllnode* cpos; //current postion;         int count; 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -