Immediatamente ecco un altro problema
codice:
>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(132) : error C2678: binary '>' : no operator found which takes a left-hand operand of type 'const Arc' (or there is no acceptable conversion)
1> g:\uni\progetto\progetto\arc.h(12): could be 'bool Arc::operator >(const Arc &)'
1> while trying to match the argument list '(const Arc, const Arc)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(131) : while compiling class template member function 'bool std::greater<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=Arc
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\queue(223) : see reference to class template instantiation 'std::greater<_Ty>' being compiled
1> with
1> [
1> _Ty=Arc
1> ]
1> g:\uni\progetto\progetto\progetto.cpp(29) : see reference to class template instantiation 'std::priority_queue<_Ty,_Container,_Pr>' being compiled
1> with
1> [
1> _Ty=Arc,
1> _Container=std::vector<Arc>,
1> _Pr=std::greater<Arc>
1> ]
Il codice interessato dall'errore è il seguente:
codice:
typedef vector<priority_queue<Arc, vector<Arc>, greater<Arc>>> vpq;
void stampaVPQ (vpq a, string s)
{
for (int k=0; k<a.size(); k++)
{
priority_queue<Arc, vector<Arc>, greater<Arc> > temp= a[k];
int cont=0;
while(!temp.empty())
{
Arc ramo= temp.top();
temp.pop();
cout<< s << "[" << k << "][" << ramo.getId() << "]: " << ramo.getW() << endl;
cont++;
}
}
}
Con Arc:
codice:
Class Arc
{
public:
Arc();
Arc(int id0, double w0);
bool operator< (const Arc &a);
bool operator> (const Arc &a);
bool operator== (const Arc &a);
bool operator>= (const Arc &a);
bool operator<= (const Arc &a);
void operator= (const Arc &a);
const int getId();
const double getW();
private:
int id;
double w;
};
...
bool Arc::operator< (const Arc &a)
{
return w < a.w;
}
bool Arc::operator > (const Arc &a)
{
return w > a.w;
}
...
Da quel che capisco mi dice che non può usare il > per riordinare la priority_queue, come se ci fosse un errore nell'overloading.
Però l'ho provato su degli arc non in una lista e funziona tutto...
Nel momento di usarlo ocme funzione di oridnamento no invece.
Non so proprio dove sbatterci la testa