0
votes

Set.h file contains in the public class :

 friend const Set operator +(const Set & a, const Set & b);

Set.cpp file contains a function called:

const Set Set::operator +(const Set & a, const Set & b)

Why is it this error appears: 'const Set Set::operator+(const Set&, const Set&)' must take either zero or one argument'

-edit-

As couple of you guys suggested , removing friend front my .h file lead to two more errors

Set.h:23:53: error: 'const Set Set::operator+(const Set&, const Set&)' must take either zero or one argument const Set operator +(const Set & a, const Set & b);

Set.cpp:73:55: error: 'const Set Set::operator+(const Set&, const Set&)' must take either zero or one argument const Set Set::operator +(const Set & a, const Set & b){

-edit 2 -

const Set operator +(const Set & a, const Set & b){
Node * intersection; 
while(a != nullptr && b != nullptr){
   if(a->value < b->value){
      intersection -> value = a;
      intersecioon = intersection->next;
      a=a->next;
   }
   if(a->value > b->value){
      intersection -> value = b;
      intersecioon = intersection->next;
      b=b->next;
   }
}
while(a != nullptr){
      intersection -> value = a;
      intersecioon = intersection->next;
      a=a->next;
}
while(b != nullptr){
      intersection -> value = b;
      intersecioon = intersection->next;
      b=b->next;
}
return intersection;
}

This is my operator function.

2
don't remove friend, remove Set:: from the second line, i.e. in the cpp file, define it as const Set operator+(const Set & a, const Set & b). If still have problems, post a MCVE stackoverflow.com/help/mcvevsoftco
many more errors, added function for more detailsuser3249265

2 Answers

2
votes

According to the declaration in Set.h, operator+ is a non-member friend function of Set. In Set.cpp, you are trying to define it as you would define a member function. The correct definition would have this signature:

const Set operator +(const Set & a, const Set & b)
0
votes

Just remove Set:: from the definition in the .cpp file.

The header file is declaring operator+ as a non-member function, so there's no reason for it to be prefixed by Set:: in the declaration. That would be needed to define a member function of the class type Set.