Bonjour à tous..
J'ai un problème avec un travail scolaire. J'ai écris un programme qui utilise une file de priorite à la facon d'un spooler. Tout semble fonctionner mais j'ai ces erreurs à la compilation:
/usr/lib/gcc/i586-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp ]’:
/usr/lib/gcc/i586-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_heap.h:279: instantiated from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator ]’
/usr/lib/gcc/i586-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_heap.h:404: instantiated from ‘void std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator ]’
/usr/lib/gcc/i586-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_queue.h:353: instantiated from ‘std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp ]’
../main.cpp:81: instantiated from here
/usr/lib/gcc/i586-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_function.h:227: erreur: no match for ‘operator<’ in ‘__x < __y’
../main.cpp:62: note: candidats sont: bool operator<(Tache&, Tache&)
make: *** [main.o] Erreur 1
Il semblerait que la redéfinition des opérateurs ne fonctionne pas et ni moi ni mon professeur ne trouvons pourquoi..
Si ca vous tente de défier un prof du cegep vous êtes les bienvenus
/** var: char Option, Choix de l'utilisateur */
char option;
/** var: string optionSaisie, le string lu lors de la saisie du choix*/
string optionSaisie;
}
else{
cout<<"Impossible d'utiliser ce nom, soit la file est pleine,"<<endl;
cout<<"soit le nom existe deja"<<endl;
}
}
break;
//menu test du tableau de pointeurs
case 'e':
{
Tache val;
int taille = spool.size() ;
int cnt = 1 ;
bool ok = false;
string nom;
priority_queue<Tache, deque<Tache> > temp ;
cout<<"Quel est le nom de la tache que vous voulez enlever?"<<endl;
getline(cin,nom);
// Menu comparer deux chaines
case 'i':{
if(stop = false){
if(spool.size()>0 ){
Tache val;
val = spool.top();
cout<<"impression de "<<val.getNom()<<" "<<val.getPriorite()<<endl;
spool.pop();
}
else cout<< "La file d'impression est vide"<<endl;
}
else cout<<"Impossible d'imprimer en ce moment"<<endl;
}
break;
// Menu phrases alléatoires
case 'f':{
Tache val;
int taille = spool.size() ;
int cnt = 1 ;
priority_queue< Tache, deque<Tache> > temp ;
Je sais pas si ça répond exactement à ton problème mais voilà un bout de code trouvé en 10s avec google code search qui montre comment implémenter une priority_queue avec les opérations de comparaison.
// rak - Rakshasa's toolbox
// Copyright (C) 2005-2006, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RAK_PRIORITY_QUEUE_DEFAULT_H
#define RAK_PRIORITY_QUEUE_DEFAULT_H
#include <stdexcept>
#include <rak/functional.h>
#include <rak/functional_fun.h>
#include <rak/priority_queue.h>
#include <rak/timer.h>
namespace rak {
class priority_item {
public:
priority_item() {}
~priority_item() {
if (is_queued())
throw std::logic_error("priority_item::~priority_item() called on a queued item.");
m_time = timer();
m_slot.set(NULL);
}
bool is_valid() const { return m_slot.is_valid(); }
bool is_queued() const { return m_time != timer(); }
void call() { m_slot(); }
void set_slot(function0<void>::base_type* s) { m_slot.set(s); }
const timer& time() const { return m_time; }
void clear_time() { m_time = timer(); }
void set_time(const timer& t) { m_time = t; }
bool compare(const timer& t) const { return m_time > t; }
private:
priority_item(const priority_item&);
void operator = (const priority_item&);
timer m_time;
function0<void> m_slot;
};
struct priority_compare {
bool operator () (const priority_item* const p1, const priority_item* const p2) const {
return p1->time() > p2->time();
}
};
typedef std::equal_to<priority_item*> priority_equal;
typedef priority_queue<priority_item*, priority_compare, priority_equal> priority_queue_default;
inline void
priority_queue_perform(priority_queue_default* queue, timer t) {
while (!queue->empty() && queue->top()->time() <= t) {
priority_item* v = queue->top();
queue->pop();
v->clear_time();
v->call();
}
}
inline void
priority_queue_insert(priority_queue_default* queue, priority_item* item, timer t) {
if (t == timer())
throw std::logic_error("priority_queue_insert(...) received a bad timer.");
if (!item->is_valid())
throw std::logic_error("priority_queue_insert(...) called on an invalid item.");
if (item->is_queued())
throw std::logic_error("priority_queue_insert(...) called on an already queued item.");
if (queue->find(item) != queue->end())
throw std::logic_error("priority_queue_insert(...) item found in queue.");
item->set_time(t);
queue->push(item);
}
inline void
priority_queue_erase(priority_queue_default* queue, priority_item* item) {
if (!item->is_queued())
return;
// Check is_valid() after is_queued() so that it is safe to call
// erase on untouched instances.
if (!item->is_valid())
throw std::logic_error("priority_queue_erase(...) called on an invalid item.");
// Clear time before erasing to force it to the top.
item->clear_time();
if (!queue->erase(item))
throw std::logic_error("priority_queue_erase(...) could not find item in queue.");
if (queue->find(item) != queue->end())
throw std::logic_error("priority_queue_erase(...) item still in queue.");
}
}
#endif
Déjà il y a un const mal placé dans la définition de ta classe, et puis tu écris tes codes avec un syntaxe correcte mais très étrange. Essaye de formater tout ça de manière plus conventionnelle... du genre :
Ca serait déjà pas mal.
Pour ton const, c'est à cette ligne, je te laisse trouver l'erreur :
int getPriorite(){return priorite;} const
Pour ton opérateur, afin de trouver l'erreur, il faudrait déjà régler ce qui est lié à la syntaxe et puis ajouter des balises pour le code (le bouton CODE en haut quand tu écris un message), nous donner les lignes où ça foire de manière claire ... En gros nous donner les informations de manières plus précises et claires.