I have a class , named Set,and I want to overload the operator - so I can get the difference between 2 Set object.
i.e. A={1,2,3,4} , B={ 3,4,5,6} , A-B={1,2}
In header file I declared the operator function like this :
Set operator-(const Set & ) ;
In the definition file :
Set Set::operator -(const Set & a)
{
int dif,i,j,k;// some handy variables
Set f; // the object who's gonna be returned by the function
f.size=0;// setting the size to 0 for now
for(i=0;i<size;i++)
{
dif=0;
for(j=0;j<a.size;j++)
{
if(ptr[i]==a.ptr[j])
++dif;
}
if(dif==0)
f.ptr[f.size++]=ptr[i]; //if an element wasn't found,in the //other set , assign it to the f object .
}
return f;
}
In Visual Studio 2005 I'm getting
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
and
error C2511: 'Set Set::operator -(const Set &)' : overloaded member function not found in 'Set'
:'(