Hey, I'm having an issue with this array within my overloaded << opperator. It keeps saying:
No operator "[]" matches these operands.
The set function is working properly
1 2 3 4 5 6 7 8 9 10 11
ostream& operator<< (ostream& out, const BitArray& ba)//OR I can simply do a int to binary conversion
{
for(int j = 0; j < 5; j++)//Arraysize wont work?
for(int i = 0; i < BITS_PER_BYTE; i++)
{
if(ba[j].Set(i)==1)// <- Issue here
out << "1";
else
out << "0";
}
}
How are you actually calling this function? It doesn't appear that you are passing any kind of array to the function. It looks like you're passing a single instance of your class not an array.
Also Set() is not returning anything so you can't do the comparison in the if statement.
Why are you calling a function with the name "Set" in an output function? Should you maybe be using a different function?
All I'm saying is that you can't use ba[j]. By default, the [] operator is only used for arrays. So, there are only two ways that ba[j] would be valid code. Either ba is an array of BitArray objects, or else you defined the [] operator for your BitArray class.
Now I have no idea how you're using the function, or what your class is supposed to do, but I'm going to guess that you don't want to pass an array to that function. In which case you shouldn't change
What you should do is figure out what you meant by ba[j] and replace that with code that actually means something.
As for the other errors you got:
error C2228: left of '.Set' must have class/struct/union
That would be because ba[j] doesn't mean anything, it's totally undefined. It's not a BitArray object, so it doesn't have a Set function.
type qualifier is not compatable with this memeber function
That would be because you changed the function definition without changing the function protocol in your class definition. Which you can forget about since, as I said, you probably weren't trying to pass an array.