title: A function inside a struct C++
body: <pre><code>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];
  </code></pre>
  
  <p>I sought a solution to Ant Colony problem in CodeForces and stumbled on <a href="https://w84iit.wordpress.com/2017/06/20/ant-colony-solutioncodeforces/" rel="nofollow noreferrer">https://w84iit.wordpress.com/2017/06/20/ant-colony-solutioncodeforces/</a>. The thing that confused me the most was this <code>struct</code> part. Is that a declaration of function inside a struct? I also see that there's function overloading in <code>struct</code> too. I am not quite familiar with a function inside <code>struct</code>, as Google search also shows that it's more common to pass <code>struct</code>s to an outer function. How do struct functions work? Can they only modify the variables declared inside the <code>struct</code>? Can I return something? The example above only used the function inside <code>struct</code> to modify its variable values.</p>