1

I'm trying to build a custom list implementation (for exercise purpose). Currently I have created an implementation with cursors and the usual one with pointers (circular doubly-linked list). I don't want to create different generic functions (print list, natural merge sort, etc.) in which the only difference is the class used). So I created an abstract class with pure virtual methods to use it as an interface. I used conditional compilation to deal with the different implementation of the position type (an int in the cursor implementation and a pointer to a node in the circular doubly-linked list). However I have these errors:

overriding 'Cella<T>* Lista<T>::primoLista() const [with T = char; Lista<T>::posizione = Cella<char>*]'
overriding 'Cella<T>* Lista<T>::primoLista() const [with T = char*;  Lista<T>::posizione = Cella<char*>*]'
overriding 'Cella<T>* Lista<T>::primoLista() const [with T = float; Lista<T>::posizione = Cella<float>*]'
overriding 'Cella<T>* Lista<T>::primoLista() const [with T = int; Lista<T>::posizione = Cella<int>*]'

I'll write the main files.

Lista.h

#ifdef USE_CURSOR
   #include "Cella.h"
#else
   #include "cellalp.h"
#endif


template <class T> class Lista
{
public:

#ifdef USE_CURSOR
    typedef int posizione;
#else
    typedef Cella<T>* posizione;
#endif

    virtual void insLista(T elem, posizione p) = 0;
    virtual void cancLista(posizione p) = 0;
    virtual bool listaVuota() const = 0;
    virtual T leggiLista(posizione p) const = 0;
    virtual void scriviLista(T elem, posizione p) = 0;
    virtual posizione primoLista() const = 0;
    virtual bool fineLista(posizione p) const = 0;
    virtual posizione succLista(posizione p) const = 0;
    //virtual posizione predLista(posizione p) const = 0;

 };

cellalp.h

template <class T> class Cella
  {
  public:
    typedef T tipoelem;
    Cella();
    Cella(tipoelem);
    void setElemento(tipoelem);
    tipoelem getElemento() const;
    void setSucc(Cella*);
    Cella* getSucc() const;
    void setPrec(Cella*);
    Cella* getPrec() const;
    bool operator ==(Cella);
  private:
    tipoelem elemento;
    Cella* prec;
    Cella* succ;
  };

// Implementazione della classe CellaLista
// --------------------------------------

// costruttori
template <class T> Cella<T>::Cella()
{}

template <class T> Cella<T>::Cella(tipoelem e)
{
  elemento = e;
}

template <class T> void Cella<T>::setElemento(tipoelem label)
{
  elemento = label;
}

template <class T>  T Cella<T>::getElemento() const
{
    return elemento;
}

template <class T> void Cella<T>::setSucc(Cella<T>* p)
{
  succ=p;
}

template <class T> Cella<T>* Cella<T>::getSucc() const
  {
    return succ;
  }

template <class T> void Cella<T>::setPrec(Cella<T>* p)
{
  prec=p;
}

template <class T> Cella<T>* Cella<T>::getPrec() const
  {
    return prec;
  }

// sovraccarico dell'operatore ==
template <class T> bool Cella<T>::operator==(Cella<T> cella)
{
  return (getElemento == cella.getElemento);
}

listap.h

#include "Lista.h"
#include <iostream>
using namespace std;

template<class T>
class circLista : public Lista<T>
  {
  public:
    circLista();
    ~circLista();
    // circLista(const circLista<T>&);
    /* posizione è un puntatore a cella */
    typedef Cella<T>* posizione;
    typedef T tipoelem;
    /* Prototipi degli operatori */
    void crealista();
    bool listaVuota() const;
    tipoelem leggiLista(posizione) const;
    void scriviLista(tipoelem, posizione);
    posizione primoLista() const;
    bool fineLista(posizione) const;
    posizione succLista(posizione) const;
    posizione precLista(posizione) const;
    void insLista(tipoelem,posizione);
    void cancLista(posizione);
    // funzioni di servizio
  private:
    posizione lista; //la lista è un puntatore ad oggetto Cella
  };

/* Liste: Rappresentazione collegata circolare (con sentinella)
 * realizzata mediante doppi puntatori (o simmetrica)
 */

template <class T> circLista<T>::circLista()
{crealista();}

template <class T> circLista<T>::~circLista()
{
    while (lista->getSucc() != lista->getPrec())
    {
       Cella<T>* posizione = lista->getSucc();
       cancLista(posizione);
    }
    delete lista;
}

template <class T> void circLista<T>::crealista()
{
  T ElementoNullo;
  lista = new Cella<T>;
  lista->setElemento(ElementoNullo);
  lista->setSucc(lista);
  lista->setPrec(lista);
  //la sentinella punta a se stessa
}

template <class T> bool circLista<T>::listaVuota() const
  {
    return ((lista->getSucc() == lista) &&  (lista->getPrec()==lista));
  }

template <class T> Cella<T>* circLista<T>::primoLista() const
  {
    return lista->getSucc();
  }

template <class T> Cella<T>* circLista<T>::succLista(posizione p) const
  {
    return p->getSucc();
  }

template <class T> Cella<T>* circLista<T>::precLista(posizione p) const
  {
    return p->getPrec();
  }

template <class T>  bool circLista<T>::fineLista(posizione p) const
  {
    return (p==lista);
  }

template <class T> T circLista<T>::leggiLista(posizione p) const
  {
    return p->getElemento();
  }

template <class T> void circLista<T>::scriviLista(tipoelem a, posizione p)
{
  p->setElemento(a);
}

template <class T> void circLista<T>::insLista(tipoelem a, posizione p)
{
  Cella<T>* temp = new Cella<T>;
  temp->setElemento(a);
  temp->setPrec(p->getPrec());
  temp->setSucc(p);
  (p->getPrec())->setSucc(temp);
  p->setPrec(temp);
  p=temp; // se p era la posizione dell'elemento n-mo, adesso lo è temp
}

template <class T> void circLista<T>::cancLista(posizione p)
{
  Cella<T>* temp = new Cella<T>;
  temp=p;
  (p->getSucc())->setPrec(p->getPrec());
  (p->getPrec())->setSucc(p->getSucc());
  p=p->getSucc();
  delete(temp);
}

Sorry for the language used in the code comments (it's italian).

Could someone explain me how to deal with these errors?

DarthVi
  • 11
  • 5
  • I understand the comments but other people might not. Anyway you posted way too much code, you should narrow your problem down and then post the relevant parts here. – Marco A. Nov 08 '14 at 14:40
  • 1
    You've pasted only a part of the error and left out the crucial part. – jrok Nov 08 '14 at 14:41
  • According to the compiler, the error is in line 30 of Lista.h, specifically on: "virtual posizione primoLista() const = 0;" I don't know if posting the TestMain.cpp could help, since I already have posted too much code and you have pointed that out. – DarthVi Nov 08 '14 at 14:58
  • @DarthVi Post a full compiler error please, you only gave us a part of it. – Barry Nov 08 '14 at 15:00
  • overriding 'Cella* Lista::primoLista() const [with T = char; Lista::posizione = Cella*]' Lista.h /Lista line 30 C/C++ Problem – DarthVi Nov 08 '14 at 15:03
  • 1
    That is not the full error. – Barry Nov 08 '14 at 15:11
  • In case you don't know, you can edit the question (the link is just under the tags). – jrok Nov 08 '14 at 15:14

1 Answers1

0

I "solved" the issue by creating another project folder in eclipse-cdt and importing only the files I needed in the specific test (the TestMain.cpp uses the abstract class Lista, the derived class circLista and not ListaCursori, so I don't need both of them in the same project). I checked many times the #include statements in the old project folder and nothing seemed to be wrong. I think that maybe Eclipse messes up something during the compile or linkage process (using both ListaCursori and circLista, thus the override errors appears). There was no makefile to analyze for further investigation in Debug or Release folders, since I use CDT Internal Builder in the Tool Chain Editor settings (source: Where is the Makefile generated by the Eclipse CDT?). Anyway I wouldn't be surprised, because it's not the first time Eclipse does "strange" things on Windows (if it really is its fault). Thanks everyone for trying to help me even if the main question was not so clear.

Community
  • 1
  • 1
DarthVi
  • 11
  • 5