¿are we suppossed to guess the implementation details of your class?
You say that `+=' should append but it does not, perhaps the problem is with its code.
Or perhaps it isn't receiving the right arguments, so blame `slice()' or your usage of it
Or the problem may be in your print algorithm.
A testcase consisting of randomly copy&paste'd bits of code that you thought were relevant can obviously not reproduce the problem.
1 2 3 4 5 6 7 8 9 10 11
// Appends a BitArray Object
BitArray& operator+=(const BitArray& b)
{
if (capacity() == used_bits) //¿you don't need to consider `b'?
Bit_Vector.resize(Bit_Vector.size() + Bit_Vector.size()); //¿is this enough? ¿what if `b' is really big?
for (size_t i = 0; i < used_bits; ++i) { //in the next line you are traversing `b', so b.used_bits
copy(used_bits - 1, b[i]); //no idea what does this function do, ¿why the first argument remains constant?
}
used_bits++; //¿so you just added only one bit?
return *this;
}
I'm trying to add the value of b, which in this case is '0100', to *this, which is the value of '010'. My end result is suppose to be '0100100' but I'm getting '0100' instead.
¿why is it so hard for you to provide your full code?
add b, which in this case is '0100', (4 bits)
to *this, which is the value of '010'. (3 bits)
result is suppose to be '0100100' (7 bits)
but I'm getting '0100' (4 bits)
I'm going to suppose that `used_bits' is the quantity of bits that you've got. (so this->used_bits is 3 and b.used_bits is 4)
In your code you do used_bits++; increasing in just 1 unit, but you need to increase it in 4 used_bits += b.used_bits; (however this invariance should be handled by your insert_at_the_end() function, which you've called copy())
In the loop you do for (size_t i = 0; i < used_bits/*3*/; ++i) when trying to add the bits of `b', you'll miss the last one.