I have to combine both objects together and add the duplicated character's counts together.
class assign_obj{
private:
struct item{
char value;
int count;
};
std::vector<item> A;
int size;
public:
//will combine the two objects together. If both objs have the same value the counts should be added together.
//this function should call compact on both objects before combining
friend const assign_obj operator+(assign_obj &,assign_obj &);
};
const assign_obj operator+(assign_obj & obj1,assign_obj & obj2){
for(int i = 0; i < obj2.A.size(); i++){
obj1.A.push_back(obj1.item()); <---- issue here.
//Add the unduplicated elements from obj2 to obj1
}
return obj1;
}
I already figured out how to add the duplicated counts but how do I add the unduplicated characters to one of the vectors?