class test{
public:
test(){};
void changeJ(int a) {j += a;}
int i = 1;
int j = 0;
};
struct comparator {
bool operator()(test a, test b) {
return a.i > b.i;
}
};
int main(int argc, char const *argv[])
{
priority_queue<test, std::vector<test>, comparator> heap;
test a;
heap.push(a);
heap.top().changeJ(1);
return 0;
}
优先级队列按i排序,我需要修改j,但是, 我得到的错误就在这一行:
heap.top().changeJ(1);
error:assignmentiof member test::j n read-only object
我该如何解决?