0

What is the meaning of the line int operator ()(int n) ?

It looks like a function but what is it?

class collatzer
{
private:
    int counter = 0;

public:
    int operator ()(int n)
    {
        if(n==1)
            return counter;

        else if(n%2==0) //if n is even
        {
            counter += 1;
            return (*this)(n / 2);
        }
        else
        {
            counter += 1;
            return (*this)(3 * n + 1);
        }
    }

    int getCounter()
    {
        return counter;
    }
};
Cœur
  • 37,241
  • 25
  • 195
  • 267
Ali Hasan
  • 149
  • 7

0 Answers0