Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di drudox
    Registrato dal
    Sep 2011
    Messaggi
    93

    eredita da lista per creare una pila

    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 :

    codice:
    	bool isStackEmpty() 
    	{
    	    return isEmpty();
    	}
    	void printStack()const 
    	{
    	  print();
    	}
    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:
    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
    qualcuno saprebbe gentilemnte illuminarmi in merito ??
    C
    C Saluti .. Il DrudoX
    C
    STOP
    END

  2. #2
    Utente di HTML.it L'avatar di drudox
    Registrato dal
    Sep 2011
    Messaggi
    93
    risolto ..

    necessario mettere un this esplicito in tutti e due i casi :
    codice:
    	bool isStackEmpty() 
    	{
    	    return this->isEmpty();
    	}
    	void printStack()const 
    	{
    	  this->print();
    	}
    C
    C Saluti .. Il DrudoX
    C
    STOP
    END

  3. #3
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,322

    Moderazione

    Il linguaggio va obbligatoriamente indicato anche nel titolo, come da Regolamento.

    Qui l'ho aggiunto io, tienilo a mente per il futuro.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.