我编写了以下代码来接收许多输入,然后按特定顺序输出它们。
#DEFINE cases 100
struct job
{
int w;
};
class compjob
{
public:
bool operator()( job j1,job j2)
{
if(j2.w>j1.w)
return true;
return false;
}
};
int main()
{
priority_queue< job, vector<job>, compjob > jobs;
int weight;
for(int i=1;i<=cases;i++)
{
cin>>weight;
job job1;
job1.w=weight;
jobs.push(job1);
} //for loop ends here
for(int i=1;i<=cases;i++)
{
job job1= jobs.pop(); ////////////ERROR!!!!!/////////
cout<<job1.w<<endl;
}
return 0;;
}
但是当我编译代码时,上面标记的行显示编译错误:
Invalid conversion from 'void' to non scalar 'job'.
我认为我没有正确声明作业 priority_queue。另外,请说明声明中第二个参数的意义(即vector,我不太清楚它的用途)