0

cliques is my class object. All my class commands work when I use them in my main but for some reason I cannot make changes to my heaps or stacks through my functions. I tried using reference markers on my function parameters but still I'm having ussues. Maybe I've done the reference incorrectly. Does anyone have any ideas what I might be doing wrong?

This is one of my functions:

void UpdateTopK(cliques C, vector<cliques> minheap) {
if (C.getclique_size() < CliqueSize) {
    return;
}
else if (minheap.size() < Solutions) {
    minheap.push_back(C);
    push_heap(minheap.begin(), minheap.end(), min_iterator());
}
else if (minheap.size() == Solutions and C.getMaxclique_prob() > minheap.front().getMaxclique_prob()) {
    pop_heap(minheap.begin(), minheap.end(), min_iterator());
    minheap.pop_back();
    minheap.push_back(C);
    push_heap(minheap.begin(), minheap.end(), min_iterator());
}

This is part of my main:

stack <cliques> cstack;
vector<cliques> max_heap;
make_heap(max_heap.begin(), max_heap.end(), max_iterator());
vector<cliques> min_heap;
make_heap(min_heap.begin(), min_heap.end(), min_iterator());

for (int i = 0; i < 5; i++) {
    cliques temp(i);
    cstack.push(temp);
}

while (!cstack.empty()) {
    cliques temp = cstack.top();
    cstack.pop();
    bool pruned = GenerateChildren(temp, min_heap, max_heap, cstack, graph);

    if (!pruned) {
        UpdateTopK(temp, min_heap);
    }
}

1 Answers1

0

You are passing arguments by value, this implies that parameters are copied before being passed to the function.

So every modification inside a method refers to the local copy only. Try passing values by references, eg:

void UpdateTopK(cliques& C, vector<cliques>& minheap)
                       ^                   ^

Mind that an object that needs to be passed to a function without copy and without being edited should be passed by const T& to specify this.

Jack
  • 131,802
  • 30
  • 241
  • 343