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 double
s and one is a std::vector
of Set
s (not std::set
s, teacher provided Set
s).
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.