2014-11-08 2 views
1

연습용으로 사용자 지정 목록 구현을 작성하려고합니다. 현재 나는 커서와 포인터 (원형 이중 연결리스트)를 가진 일반적인 구현을 만들었습니다. 유일한 차이점은 사용되는 클래스가 다른 일반 함수 (인쇄 목록, 자연 병합 정렬 등)를 만들고 싶지 않습니다. 그래서 순수 가상 메서드를 사용하여 추상 클래스를 만들어 인터페이스로 사용했습니다. 조건부 컴파일을 사용하여 위치 유형 (커서 구현의 int 및 순환 이중 연결 목록의 노드에 대한 포인터)의 다른 구현을 처리했습니다. 그러나 나는이 오류가있다 :추상 템플릿 기반 클래스에서 C++ 재정의 오류

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>*]' 

나는 주 파일을 쓸 것이다.

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); 
} 

코드 주석 (는 이탈리아어입니다)에서 사용되는 언어에 대한 죄송합니다.

누군가 이러한 오류를 처리하는 방법을 설명해 주시겠습니까?

+0

나는 의견을 이해하지만 다른 사람들은 그렇지 않을 수도 있습니다. 어쨌든 너무 많은 코드를 게시 한 경우 문제를 줄이고 여기에 관련 부분을 게시해야합니다. –

+1

오류의 일부만 붙여 넣어 중요한 부분을 빠져 나갔습니다. – jrok

+0

컴파일러에 따르면이 오류는 특히 Lista.h의 30 행에 있습니다. "virtual posizione primoLista() const = 0;" TestMain.cpp를 게시하면 도움이 될지 모르겠다. 이미 너무 많은 코드를 게시 했으므로 지적했다. – DarthVi

답변

0

는 그래서, 이클립스 CDT의 다른 프로젝트 폴더를 생성하고 내가 특정 테스트에 필요한 파일 만 가져 와서 문제가합니다 (TestMain.cpp는 추상 클래스 Lista, 파생 클래스 circLista하지 ListaCursori를 사용합니다 "해결" 두 프로젝트가 같은 프로젝트에서 필요하지는 않습니다.) 이전 프로젝트 폴더에있는 #include 문을 여러 번 확인했는데 아무 문제가없는 것 같았습니다. 아마 이클립스가 컴파일이나 링키지 과정에서 무언가를 엉망으로 만든다고 생각한다. (ListaCursoricircLista을 모두 사용하여 오버라이드 오류가 나타난다.) 도구 체인 편집기 설정 (출처 : Where is the Makefile generated by the Eclipse CDT?)에서 CDT Internal Builder을 사용 했으므로 Debug 또는 Release 폴더에서 추가 조사를 위해 분석 할 메이크 파일이 없었습니다. 어쨌든 Eclipse가 Eclipse에서 "이상한"일을하는 것은 처음이 아니기 때문에 어쨌든 나는 놀라지 않을 것입니다. 주요 질문이 분명하지 않은 경우에도 도움을 주신 모든 분들께 감사드립니다.

관련 문제