struct segment{
int _gcd;
int _count;
segment(){
_gcd=0;
_count=0;
}
segment(int val)
{
_gcd=val;
_count=1;
}
void mergee(segment left,segment right)
{
_count=0;
_gcd=gcd(left._gcd,right._gcd);
if(_gcd==left._gcd)
{
_count+=left._count;
}
if(_gcd==right._gcd)
{
_count+=right._count;
}
}
}seg[4*N];
I sought a solution to Ant Colony problem in CodeForces and stumbled on https://w84iit.wordpress.com/2017/06/20/ant-colony-solutioncodeforces/. The thing that confused me the most was this struct
part. Is that a declaration of function inside a struct? I also see that there's function overloading in struct
too. I am not quite familiar with a function inside struct
, as Google search also shows that it's more common to pass struct
s to an outer function. How do struct functions work? Can they only modify the variables declared inside the struct
? Can I return something? The example above only used the function inside struct
to modify its variable values.