K
Kelvin Moss
Hi all,
I was trying to use priority queues and wrote a sample code. g++
accepted the code but Comeau online doesn't. I can't figure out what
Comeau is complaining about. Could anyone please suggest?
#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
struct Person {
string name;
int age;
Person(string n, int i):name(n), age(i)
{}
};
struct Comp {
bool operator()(const Person &p1, const Person &p2) {
if (p1.age > p2.age) {
return true;
} else {
return false;
}
}
};
int main()
{
priority_queue<Person, vector<Person>, Comp> q;
q.push(Person("XXX", 28));
q.push(Person("BBBB", 42));
q.push(Person("CCC", 75));
q.push(Person("DDD", 51));
while (!q.empty()) {
cout << q.top().name << endl;
q.pop();
}
}
Comeau cribs like --
"sequence_concepts.h", line 31: error: no instance of constructor
"Person:erson" matches the argument list
typename _XX::value_type __t = typename _XX::value_type();
^
detected during:
instantiation of "void
_ERROR_IN_STL_SEQ::__fill_constructor_requirement_violati
on(_XX &) [with _XX=std::vector<Person,
std::allocator<Person>>]" at line 164
instantiation of "void
_Sequence_concept_specification<_Sequence>::_Sequence_req
uirement_violation(_Sequence) [with
_Sequence=std::vector<Person,
std::allocator<Person>>]"
at line 26 of "ComeauTest.c"
May be I am missing something?
TIA ..
I was trying to use priority queues and wrote a sample code. g++
accepted the code but Comeau online doesn't. I can't figure out what
Comeau is complaining about. Could anyone please suggest?
#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
struct Person {
string name;
int age;
Person(string n, int i):name(n), age(i)
{}
};
struct Comp {
bool operator()(const Person &p1, const Person &p2) {
if (p1.age > p2.age) {
return true;
} else {
return false;
}
}
};
int main()
{
priority_queue<Person, vector<Person>, Comp> q;
q.push(Person("XXX", 28));
q.push(Person("BBBB", 42));
q.push(Person("CCC", 75));
q.push(Person("DDD", 51));
while (!q.empty()) {
cout << q.top().name << endl;
q.pop();
}
}
Comeau cribs like --
"sequence_concepts.h", line 31: error: no instance of constructor
"Person:erson" matches the argument list
typename _XX::value_type __t = typename _XX::value_type();
^
detected during:
instantiation of "void
_ERROR_IN_STL_SEQ::__fill_constructor_requirement_violati
on(_XX &) [with _XX=std::vector<Person,
std::allocator<Person>>]" at line 164
instantiation of "void
_Sequence_concept_specification<_Sequence>::_Sequence_req
uirement_violation(_Sequence) [with
_Sequence=std::vector<Person,
std::allocator<Person>>]"
at line 26 of "ComeauTest.c"
May be I am missing something?
TIA ..