Salve a tutti .. sto provando a realizzare una semplice pila .. che deriva con eredita di tipo private da una lista, (uso l'eredita` private in modo da poter usare solo dei metodi che delegano le funzioni membro private ereditate da list )
la definizione di list e` la seguente
codice:template<typename NT> class List{ public : List(); // constructor ~List(); // destructor void InsertAtFront( const NT & ); void InsertAtBack( const NT & ); bool removeFromFront( NT &); bool removeFromBack( NT &); bool isEmpty()const; // return true if list is empty void print()const; private: ListNode<NT> *firstPtr; ListNode<NT> *lastPtr; // ListNode<NT> * getNewNode( const NT &); };
la classe Stack che e` eredita` con eredita` private e` la seguente :
codice:#ifndef STACK_H #define STACK_H # include "list.h" # include <iostream> //using namespace std; template<typename T> class Stack :private List<T> { public : void push(const T& value){ insertAtFront(value) ; } bool pop(T&value){ return removeFromFront(value); } bool isStackEmpty() { return isEmpty(); } void printStack()const { print(); } }; #endif
ora .. se commento il blocco di funzioni :
fila tutto liscio .. crea una pila .. etc .. e anche con l'opzione -fpermissive la compilazione va a termine .. e il programma viene eseguito .. cio` nonostante riscontro i seguenti errori (che poi diventano warning se uso -fpermissive)codice:bool isStackEmpty() { return isEmpty(); } void printStack()const { print(); }
qualcuno saprebbe gentilemnte illuminarmi in merito ??codice:In file included from pila_client.C:3: stack.h: In member function ‘bool Stack<T>::isStackEmpty()’: stack.h:25: error: there are no arguments to ‘isEmpty’ that depend on a template parameter, so a declaration of ‘isEmpty’ must be available stack.h:25: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) stack.h: In member function ‘void Stack<T>::printStack() const’: stack.h:29: error: there are no arguments to ‘print’ that depend on a template parameter, so a declaration of ‘print’ must be available

Rispondi quotando