Probleme heritage (debutant)
Salut a tous , pourriez vous m'aider a debugger mon code svp :
voila mes 4 fichiers source: (pfifo etant la classe fille de fifo)
fifo.h:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#ifndef _FIFO_H
#define _FIFO_H
template <typename ELEM, int CAPACITY>
class Fifo{
public :
Fifo() { head = 0 ; size=0 ;}
void add(ELEM);
ELEM remove();
bool is_full() const ;
bool is_empty() const ;
void print() const ;
class Full {} ;
class Empty {} ;
protected :
ELEM Tab[CAPACITY] ;
int head ;
int size ;
};
#include "fifo.cc"
#endif |
fifo.cc
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
using namespace std ;
#include "fifo.h"
template <typename ELEM, int CAPACITY>
void Fifo<ELEM,CAPACITY>::add(ELEM elem) {
//cout << "add : size="<<size<<" Head="<<head<<endl;
if ( size >= CAPACITY ) throw Full() ;
Tab[(head+size)%CAPACITY]=elem;
size++;
}
template <typename ELEM, int CAPACITY>
ELEM Fifo<ELEM,CAPACITY>::remove(){
//cout << "remove : size="<<size<<" Head="<<head<<endl;
ELEM element ;
if ( size <= 0 ) throw Empty() ;
element = Tab[head] ;
size--;
head=(head+1)%CAPACITY;
return element;
}
template <typename ELEM, int CAPACITY>
bool Fifo<ELEM,CAPACITY>::is_full() const {
return size>=CAPACITY ;
}
template <typename ELEM, int CAPACITY>
bool Fifo<ELEM,CAPACITY>::is_empty() const {
return size<=0;
}
template <typename ELEM, int CAPACITY>
void Fifo<ELEM,CAPACITY>::print() const {
//cout << "head " << head << '\n';
for(int i=0;i<size;i++){
cout << Tab[(head+i)%CAPACITY] << " ";
}
} |
pfifo.h:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#ifndef _PFIFO_H
#define _PFIFO_H
#include "fifo.h"
template <typename ELEM, int CAPACITY>
class PriorityFifo : public Fifo<ELEM,CAPACITY>{
public :
void add(ELEM);
};
#include "pfifo.cc"
#endif |
et pfifo.cc :
Citation:
#include "pfifo.h"
template <typename ELEM, int CAPACITY>
void PriorityFifo<ELEM,CAPACITY>::add(ELEM elem) {
int i = size ;
if ( size >= CAPACITY ) throw Full() ;
while ( ( elem > Tab[((head+i-1)+CAPACITY)%CAPACITY] ) && i>0 ){
//on decale
Tab[(head+i)%CAPACITY]=Tab[((head+i-1)+CAPACITY)%CAPACITY];
i--;
}
//on insere
Tab[(i+head)%CAPACITY]=elem;
size++;
}
Enfin l'erreur de compilation
Citation:
g++ -g testpfifo.cc -c
pfifo.cc: In member function ‘void PriorityFifo<ELEM, CAPACITY>::add(ELEM)’:
pfifo.cc:6: error: ‘size’ was not declared in this scope
pfifo.cc:7: error: there are no arguments to ‘Full’ that depend on a template parameter, so a declaration of ‘Full’ must be available
pfifo.cc:7: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
pfifo.cc:8: error: ‘Tab’ was not declared in this scope
pfifo.cc:8: error: ‘head’ was not declared in this scope
pfifo.cc:14: error: ‘Tab’ was not declared in this scope
pfifo.cc:14: error: ‘head’ was not declared in this scope
pfifo.cc: In member function ‘void PriorityFifo<ELEM, CAPACITY>::add(ELEM) [with ELEM = double, int CAPACITY = 3]’:
testpfifo.cc:24: instantiated from here
pfifo.cc:7: error: expected primary-expression
pfifo.cc: In member function ‘void PriorityFifo<ELEM, CAPACITY>::add(ELEM) [with ELEM = char, int CAPACITY = 10]’:
testpfifo.cc:70: instantiated from here
pfifo.cc:7: error: expected primary-expression
pfifo.cc: In member function ‘void PriorityFifo<ELEM, CAPACITY>::add(ELEM) [with ELEM = Rationnel, int CAPACITY = 5]’:
testpfifo.cc:85: instantiated from here
pfifo.cc:7: error: expected primary-expression
make: *** [testpfifo.o] Erreur 1