G ++一直在用这个巨大的错误报告来哄我。但我完全无法从中提取任何信息。如果你能帮助我,那将是很棒的。
据我所知,错误应该连接到运算符<
,它在Calendar.cpp类中定义。但无论我尝试做什么,我都会遇到越来越多的错误。
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = activationRecord]’:
/usr/include/c++/4.8.2/bits/stl_heap.h:313:40: required from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<activationRecord*, std::vector<activationRecord, std::allocator<activationRecord> > >; _Distance = long int; _Tp = activationRecord; _Compare = std::less<activationRecord>]’
/usr/include/c++/4.8.2/bits/stl_heap.h:448:15: required from ‘void std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<activationRecord*, std::vector<activationRecord, std::allocator<activationRecord> > >; _Compare = std::less<activationRecord>]’
/usr/include/c++/4.8.2/bits/stl_queue.h:399:48: required from ‘std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, const _Sequence&) [with _Tp = activationRecord; _Sequence = std::vector<activationRecord, std::allocator<activationRecord> >; _Compare = std::less<activationRecord>]’
Calendar.h:15:7: required from here
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: error: no match for ‘operator<’ (operand types are ‘const activationRecord’ and ‘const activationRecord’)
{ return __x < __y; }
^
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: candidates are:
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:64:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_pair.h:220:5: note: template<class _T1, class _T2> bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/4.8.2/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_iterator.h:297:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/4.8.2/bits/stl_iterator.h:297:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_iterator.h:347:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/4.8.2/bits/stl_iterator.h:347:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/string:52:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/basic_string.h:2569:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8.2/bits/basic_string.h:2569:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/string:52:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/basic_string.h:2581:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/4.8.2/bits/basic_string.h:2581:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/string:52:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/basic_string.h:2593:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^
/usr/include/c++/4.8.2/bits/basic_string.h:2593:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: mismatched types ‘const _CharT*’ and ‘activationRecord’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/deque:64:0,
from /usr/include/c++/4.8.2/queue:60,
from Calendar.h:2,
from Main.cpp:3:
/usr/include/c++/4.8.2/bits/stl_deque.h:273:5: note: template<class _Tp, class _Ref, class _Ptr> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _Ref, _Ptr>&)
operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
^
/usr/include/c++/4.8.2/bits/stl_deque.h:273:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/deque:64:0,
from /usr/include/c++/4.8.2/queue:60,
from Calendar.h:2,
from Main.cpp:3:
/usr/include/c++/4.8.2/bits/stl_deque.h:281:5: note: template<class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> bool std::operator<(const std::_Deque_iterator<_Tp, _Ref, _Ptr>&, const std::_Deque_iterator<_Tp, _RefR, _PtrR>&)
operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
^
/usr/include/c++/4.8.2/bits/stl_deque.h:281:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::_Deque_iterator<_Tp, _Ref, _Ptr>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/deque:64:0,
from /usr/include/c++/4.8.2/queue:60,
from Calendar.h:2,
from Main.cpp:3:
/usr/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::deque<_Tp, _Alloc>&, const std::deque<_Tp, _Alloc>&)
operator<(const deque<_Tp, _Alloc>& __x,
^
/usr/include/c++/4.8.2/bits/stl_deque.h:1975:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::deque<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/vector:64:0,
from /usr/include/c++/4.8.2/queue:61,
from Calendar.h:2,
from Main.cpp:3:
/usr/include/c++/4.8.2/bits/stl_vector.h:1420:5: note: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/4.8.2/bits/stl_vector.h:1420:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/4.8.2/queue:64:0,
from Calendar.h:2,
from Main.cpp:3:
/usr/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template<class _Tp, class _Seq> bool std::operator<(const std::queue<_Tp, _Seq>&, const std::queue<_Tp, _Seq>&)
operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)
^
/usr/include/c++/4.8.2/bits/stl_queue.h:286:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/string:48:0,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Main.cpp:1:
/usr/include/c++/4.8.2/bits/stl_function.h:235:20: note: ‘const activationRecord’ is not derived from ‘const std::queue<_Tp, _Seq>’
{ return __x < __y; }
^
make: *** [simlib] Error 1
代码本身:
#include <iostream>
#include "Calendar.h"
#include "Transaction.h"
using namespace std;
int main() {
Calendar *calendar = new Calendar();
calendar->init(0, 300);
calendar->push(0,1, new Transaction(calendar));
calendar->run();
}
----------CALENDAR.H----------
#include <iostream>
#include <queue>
using namespace std;
class Transaction;
struct activationRecord {
double time;
int priority;
Transaction *transaction;
};
class Calendar {
private:
double timeStop;
double time;
priority_queue<activationRecord> activationCalendar;
public:
bool isEmpty();
void push(double, int, Transaction*);
void pop();
void run();
void init(double, double);
double getTime();
activationRecord top();
};
----------CALENDAR.CPP----------
#include <iostream>
#include "Calendar.h"
#include "Transaction.h"
using namespace std;
bool Calendar::isEmpty() {
return activationCalendar.empty();
}
void Calendar::pop() {
activationCalendar.pop();
}
void Calendar::push(double t, int p, Transaction *tr) {
activationRecord r;
r.priority = p;
r.time = t;
r.transaction = tr;
activationCalendar.push(r);
}
activationRecord Calendar::top() {
return activationCalendar.top();
}
void Calendar::run() {
activationRecord r;
while(!activationCalendar.empty()) {
r = activationCalendar.top();
activationCalendar.pop();
if(r.time > timeStop) {
time = timeStop;
break;
}
//Posun cas na cas aktualniho eventu
time = r.time;
cout << "Time: " << time << " ";
//Vykonej event
(*r.transaction).choose();
}
}
void Calendar::init(double start, double stop) {
time = start;
timeStop = stop;
}
double Calendar::getTime() {
return time;
}
bool operator <(const activationRecord & a, const activationRecord & b)
{
return a.time > b.time;
}
----------TRANSACTION.H----------
#include <iostream>
using namespace std;
class Calendar;
class Transaction {
private:
int chooser;
Calendar *cal;
public:
Transaction(Calendar*);
~Transaction();
void choose();
void event1();
void event2();
void event3();
void event4();
};
----------TRANSACTION.CPP----------
#include <iostream>
#include "Transaction.h"
#include "Calendar.h"
using namespace std;
Transaction::Transaction(Calendar *c) {
this->cal = c;
this->chooser = 1;
}
void Transaction::choose() {
switch(chooser){
case(1):
event1();
break;
case(2):
event2();
break;
case(3):
event3();
break;
case(4):
event4();
break;
}
}
void Transaction::event1() {
cout << "Event1::Transakce" << this << endl;
chooser = 2;
cal->push(cal->getTime()+200, 1, new Transaction(cal));
cal->push(cal->getTime(), 1, this);
}
void Transaction::event2() {
cout << "Event2::Transakce" << this << endl;
chooser = 3;
cal->push(cal->getTime()+50, 1, this);
}
void Transaction::event3() {
cout << "Event3::Transakce" << this << endl;
chooser = 4;
cal->push(cal->getTime(), 1, this);
}
void Transaction::event4() {
cout << "Event4::Transakce" << this << endl;
}
答案 0 :(得分:3)
您正在尝试创建activationRecords的优先级队列,但您从未在Calendar.h
中声明了比较运算符。优先级队列无法判断哪些元素具有更高的优先级。