Mi scuso per il precedente topic, avevo dato per scontato si parlasse di C++.
Torno al mio problema.
In fase di compilazione ho questi warning:
codice:
Dictionary_Exception.h:20: warning: 'class Dictionary_Exception' has virtual functions but non-virtual destructor
Dictionary_Exception.h:27: warning: 'class EmptyError' has virtual functions but non-virtual destructor
Dictionary.h: In instantiation of 'Dictionary<int, std::string>':
RB_Tree.h:19: instantiated from 'RB_Tree<int, std::string>'
main.cpp:18: instantiated from here
Dictionary.h:15: warning: 'class Dictionary<int, std::string>' has virtual functions but non-virtual destructor
RB_Tree.h: In instantiation of 'RB_Tree<int, std::string>':
main.cpp:18: instantiated from here
RB_Tree.h:19: warning: 'class RB_Tree<int, std::string>' has virtual functions but non-virtual destructor
Dictionary_Exception.h: In instantiation of 'SearchError<int>':
RB_Tree.h:384: instantiated from 'Data RB_Tree<Key, Data>::Search(Key) [with Key = int, Data = std::string]'
main.cpp:39: instantiated from here
Dictionary_Exception.h:37: warning: 'class SearchError<int>' has virtual functions but non-virtual destructor
Dictionary_Exception.h: In instantiation of 'RemoveError<int>':
RB_Tree.h:428: instantiated from 'void RB_Tree<Key, Data>::Remove(Key) [with Key = int, Data = std::string]'
main.cpp:45: instantiated from here
Dictionary_Exception.h:50: warning: 'class RemoveError<int>' has virtual functions but non-virtual destructor
Perchè dovrei fare un distruttore virtuale?
questa la mia classe:
codice:
#ifndef DICTONARY_EXCEPTION_H_
#define DICTONARY_EXCEPTION_H_ 1
#include <iostream>
//Classe che gestisce le eccezioni nel dizionario
//Questa classe ha dei metodi in grado di rappresentare le eccezioni.
//Il programma chiamato solleverà l'errore con throw, il chiamante intrappolerà
//l'errore con catch.
//Classe base di una eccezione
class Dizionario_Exception
{
public:
virtual void debug_print() const {std::cerr << "Dictionary Error" << std::endl; }
};
//Eccezioni di dizionario vuoto
class EmptyError : public Dizionario_Exception
{
public:
virtual void debug_print() const
{
std::cerr << "Dizionario vuoto."<<std::endl;
}
};
//Eccezioni di ricerca (elemento non trovato)
template <class Key> class SearchError : public Dizionario_Exception
{
private:
Key k;
public:
SearchError(Key &key){k=key;}
virtual void debug_print() const
{
std::cerr << "Ricerca fallita, l'elemento con chiave "<<k<<" non Ë stato trovato."<<std::endl;
}
};
//Eccezioni di cancellazione (elemento non trovato)
template <class Key> class RemoveError : public Dizionario_Exception
{
private:
Key k;
public:
RemoveError(Key &key){k=key;}
virtual void debug_print() const
{
std::cout << "Cancellazione non effettuata, l'elemento con chiave "<<k<<" non Ë presente nel dizionario"<<std::endl;
}
};
#endif /* DICTONARY_EXCEPTION_H_ */