I'm writing a program that takes in two sets of numbers and removes all elements of one set from the other set. I overloaded the - operator in order to do this. My error is:
invalid types `<unknown type>[int]' for array subscript //See driver program
set::set(int array_input[], int counted)
{
used = counted;
for(int x = 0; x > used; used++)
{
data[used] = array_input[used];
}
}
bool set::erase_one(const value_type& target)
{
size_type index = 0;y
while ((index < used) && (data[index] != target))
{
++index;
}
if (index == used)
{
returnfalse;
}
--used;
data[index] = data[used];
returntrue;
}
bool set::contains(const value_type& target) const
{
size_type i;
for(i = 0; i < used; i++)
{
if(target == data[i])
{
returntrue;
}
else
{
returnfalse;
}
}
}
set operator-(const set& b1, const set& b2)
{
size_t index;
set answer(b1); // copy constructor
size_t size2 = b2.size(); // use member function size
for (index = 0; index < size2; ++index)
{
int target = b2.data[index];
if (answer.contains(target))
{
answer.erase_one(target);
}
}
return answer;
}
What my driver program is trying to do:
1 2 3 4 5 6 7
set first(array1, counter_one), second(array2, counter_two), subtraction;
subtraction = first - second;
for(int z = 0; z < subtraction.size(); z++)
{
cout << subtraction.get_array[z] << " "; //THIS IS WHERE THE ERROR IS
}
Why am I getting this error and what can I do to fix it?
Any help is appreciated. Thanks!