On Nov 11, 10:45 am, Martin Engelmann <martin.engelm...@gmx.dewrote:
Latina schrieb:
On Nov 11, 8:50 am, Martin Engelmann <martin.engelm...@gmx.dewrote:
Latina schrieb:
but I still have some other errors.
error: `isValid' undeclared (first use this function)
(where the arrow is pointing)
IntegerSet operator+(IntegerSet &right)
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
-- if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
Is operator+ a member of class IntegerSet? If it is, isValid will be
called with *this. If operator+ is not a member of class IntegerSet you
have to call it with an object.
if i use *this gives me this error
--invalid use of `this' in non-member function
So you should either make operator+ a member function of IntegerSet or
add a second parameter to the function.
IntegerSet IntegerSet::operator+(IntegerSet &right)
(my recommendation)
or
IntegerSet operator+(IntegerSet &left, IntegerSet &right)
When using a non-member function you have to change the condition to
if(left.isValid(element) || right.isValid(element))- Hide quoted text -
Ok, I declared like this and this is the error I am getting
"expected init-declarator before '+' token ":
class IntegerSet
{
public:
//Operator methods.
IntegerSet &operator+(const IntegerSet &right);
//overloaded operator + to compute the union of two sets
--IntegerSet IntegerSet::perator+(IntegerSet &right)
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}
But if I do it like this I am getting the same error
"expected init-declarator before '+' token"
//overloaded operator + to compute the union of two sets
--IntegerSet perator+( &left, IntegerSet &right)
{
IntegerSet j;
for(int element=0; element<=25; element++)
{
if(left.isValid(element) || right.isValid(element))
j.insertElement(element);
}
return j;
}