1

Hello sorry if there are any problems in this post, it's my first time using the site and I'm a little desperate.

This is for school. The teacher provided us with a ready to use the code for a Heap class and a Set class and some other stuff. Out of the classes I made myself, there's one that has 4 attributes: 3 of them are long doubles and one is a std::vector of Sets (not std::sets, teacher provided Sets).

I'm having a problem when inserting or removing objects of this class from the provided Heap. The objects inserted into the heap, when removed, are missing everything I've put on the std::vector.

A part from my main where it happens (save for debugging stuff)

PartialSolution temp; //this is the object
temp.includeSet(*s);
temp.Print(); //so far everything works fine
H.insert(temp);
PartialSolution l; 
l = H.top(); //written by teacher, gets first element from heap
l.Print(); //here the contents I've added with includeSet are gone

I'm pretty sure the problem can't be in the Heap since the teacher made it and also it uses a template clthe attributes of the objects on the objects attributes, but I really have no idea at all where the problem could be.

The vector is declared as

std::vector<Set> sets;

EDIT: Solved, thanks. (Sorry if I'm doing it wrong, I'm not sure how else to close the question). The problem was in a = operator method for PartialSolution created by the teacher, that only copied the long double attributes and was used in the Heap. Added a line to copy the std::vector and it works fine now.

  • Please [edit] your question and [format](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks/) the code. – n. m. could be an AI Nov 15 '18 at 06:42
  • 3
    Probably [slicing](https://stackoverflow.com/questions/274626/what-is-object-slicing). – Mat Nov 15 '18 at 08:51
  • 1
    When you copy objects into and out of a collection then you have to observe the "c++ rule of three". The quoted phrase is easy to google. – Hans Passant Nov 15 '18 at 10:01

0 Answers0