Errore compilazione c++

Gianni911
Ragazzi scusate,
dovrei provare degli esercizi,tramite del codice fatto dal mio prof.Il problema é che non riesco a compilare mi da sempre
" [Linker error] undefined reference to `IntGenTree::esercizio(BaseGenTree::Node*)' ".Non riesco a trovare una soluzione..
Qualcuno può aiutarmi??
Vi posto il codice..
IntGenTree.h
#ifndef INTGTREE_H
#define INTGTREE_H

#include "BaseGenTree.h"

class IntGenTree: public BaseGenTree<int>{
protected:
   /* inserire qui le intestazioni */
   static void esercizio(Node*,int);
public:
   /* inserire qui le intestazioni pubbliche */
  void _esercizio();
  
};

#endif

IntGenTree.cpp
#include "IntGenTree.h"
#include "BaseGenTree.h"

/* Inserire qui il codice */

void IntGenTree::esercizio(Node* t,int max){
   if (t == NULL) { max = 0; return 0; }
   // maxC = massimo tra i discendenti
   // maxS = massimo tra i prossimi fratelli
   int maxC, maxS;
   int count;
   count = countDescendantsRulers(t->firstChild, maxC);
   count += countDescendantsRulers(t->nextSibling, maxS);
   // max = max(t->info, maxC, maxS) = massimo globale
   if (t->info > maxC){
      // il nodo domina i suoi discendenti:
      count++;
      max = (t->info > maxS) ? t->info : maxS;
   }
   else
      max = (maxC > maxS) ? maxC : maxS;
   return count;  }


void IntGenTree::_esercizio(){ int n=5;
                               esercizio(root,n);
                                    }

BaseGenTree.h
#ifndef BASEGTREE_H
#define BASEGTREE_H

#include <iostream>
#include <iomanip>

// Necessarie per le dichiarazioni 'friend'.
template <class T> class BaseGenTree;
template <class T> std::ostream& operator<<(std::ostream&, const BaseGenTree<T>&);
template <class T> std::istream& operator>>(std::istream&, BaseGenTree<T>&);

/** 
 * Classe modello di un albero binario semplice.
 */
template <class T>
class BaseGenTree{
protected:

  /**
   * Un nodo dell'albero.
   */
  struct Node{
    
    T info;		/**< Il contenuto del nodo */
    Node* firstChild;	/**< Il puntatore al primo figlio */
    Node* nextSibling;	/**< Il puntatore al prossimo fratello */
    
    /** 
     * Costruisce un nodo di valore x.
     */
    Node(const T& x) : info(x), firstChild(NULL), nextSibling(NULL){};
  };				
  
  Node* root;			/**< Il puntatore alla radice dell'albero */
  
  static void deleteTree(Node*&);
  static std::ostream& putTo(const Node*, std::ostream&);
  static std::istream& getFrom(Node*&, std::istream&);
public:
  /** 
   * Costruisce un albero binario vuoto.
   */
  BaseGenTree() : root(NULL){};
  /** 
   * Distrugge l'albero binario.
   */
  virtual ~BaseGenTree() {deleteTree(root);};

  friend std::ostream& operator<< <>(std::ostream&, const BaseGenTree<T>&);
  friend std::istream& operator>> <>(std::istream&, BaseGenTree<T>&);  
};



/* =============== IMPLEMENTAZIONE =============== */

/** 
 * Cancella tutti i nodi dell'albero t.
 */
template <class T>
void BaseGenTree<T>::deleteTree(Node*& t) {
  if (t != NULL) {
    deleteTree(t->firstChild);
    deleteTree(t->nextSibling);
    delete t;
    t = NULL;
  }
}

/** 
 * Invia un albero su stream di output nel formato: [1[3][4[][5]]].
 */
template <class T>
std::ostream& BaseGenTree<T>::putTo(const Node* t, std::ostream& os){
   os << '[';
   if(t != NULL)
   {
      // stampo la radice:
      os << t->info;
      // stampo i sottoalberi:
      for(Node* i = t->firstChild; i != NULL; i = i->nextSibling)
         putTo(i, os);
   }      
   os << ']';
   return os;
}

/** 
 * Ridefinizione dell'operatore 'put to' per la classe BaseGenTree.
 * Invia un albero su stream di output nel formato: [1[3][4[][5]]].
 */
template<class T>
std::ostream& operator<<(std::ostream& os, const BaseGenTree<T>& t){
   return BaseGenTree<T>::putTo(t.root, os);
}

/** 
 * Acquisisce un albero da stream di input nel formato: [1[3][4[][5]]].
 */
template <class T>
std::istream& BaseGenTree<T>::getFrom(Node*& t, std::istream& is){
   deleteTree(t);

   char cbuf;
   is >> cbuf;
   if (cbuf != '['){
      is.putback(cbuf);
      is.clear(std::ios_base::failbit);
      return is;
   }
   is >> cbuf;
   if (cbuf == ']') // albero vuoto: []
      return is;
   is.putback(cbuf);
   T info;
   
   is >> info >> cbuf;
   if (is.fail()) return is;
   t = new Node(info);
   Node** subTree = &(t->firstChild);
   while (cbuf == '['){
      // acquisisco un sottoalbero:
      is.putback(cbuf);
      getFrom(*subTree, is);
      is >> cbuf;
      subTree = &((*subTree)->nextSibling);
      if (cbuf == ']'){
         return is;
      }
   }
   return is;
}

/** 
 * Ridefinizione dell'operatore 'get from' per la classe BaseGenTree.
 * Acquisisce un albero da stream di input nel formato: [1[3][4[][5]]].
 */
template <class T>
std::istream& operator>>(std::istream& is, BaseGenTree<T>& t){
   return BaseGenTree<T>::getFrom(t.root, is);
}

#endif

Il tutto gestio da
main.cpp
#include "IntGenTree.h"
using namespace std;

int main(){
    IntGenTree t;
    cout<<t<<endl;
    t._esercizio();
    system("PAUSE");
    return 0;
    }


Grazie!! :D

Risposte
Gianni911
Nessuno sa come risolvere questo problema?? :cry:

apatriarca
Più che altro credo che nessuno abbia avuto il tempo/voglia di copiare tutto il codice e provare a compilarlo. Quale compilatore stai usando e su quale sistema?

apatriarca
Gli errori di compilazione che ho ottenuto sono decisamente diversi da quello che hai postato. Per prima cosa system richiede l'inclusione di cstdlib (oppure di stdlib.h), ma è decisamente inutile e si fa prima ad eliminare la riga contenente system("PAUSE"). Inoltre IntGenTree::esercizio restituisce void, ma ci sono istruzioni per restituire dei valori da essa. Infine non sono riuscito a trovare la funzione countDescendantsRulers, che viene usata ma che non sembra essere mai stata dichiarata.

Come hai compilato il codice? Mi sembra strano che l'unico errore che hai ottenuto fosse quello.

Gianni911
Guarda avendo provato diverse funzioni,ho mischiato un po di cose.. :-D
Ti ringrazio per la risposta,ma avevo gia risolto.. :lol:

Rispondi
Per rispondere a questa discussione devi prima effettuare il login.