My code is for a class which already has an oprator<< function
friend ostream& operator<<(ostream &os, const Alist& other);
ostream& operator<<(ostream &os, const Alist& other)
{
for (int i = 0; i <= other.val; i++)
os << other.a[i] << ", ";
return os;
}
it doesn't satisfy the parameters for this statement in my main function
cout << "Double remove: " << a1.remove(n) << " " << a1.remove(n) << endl;
and I receive this error
no operator "<<" matches these operands -- operand types are: std::basic_ostream<char, std::char_traits<char>> << void
I'm not sure how to go about writing the function for another << operator but so far I have what's shown below as that seems to meet the needs.
friend ostream& operator<<(ostream &os, const unsigned char *s);
is this correct? and how would I write the function for this? Below is the remove function.
bool Alist::remove(int n)
{
for (int i = 0; i < val; i++)
if(a[i] = n)
{
for ( int j = i; j < (val - 1); j++)
a[j] = a[j+1];
}
for (int i = 0; i < val; i++)
if(a[i] != n)
return true;
else
return false;
}
Aucun commentaire:
Enregistrer un commentaire