Rekurencyjne wywołanie klasy przez samą siebie za pomocą this

0

Pytanie:

 
struct functor
{
  int operator() (int n)
  {
        void* temp = this;
        return temp(n-1)+temp(n-2);
  }
};

Czy niemozliwym jest wywolanie rekurencyjne klasy przez sama siebie za pomoca this ?

 
struct functor
{
 int operator() (int n)
  {
        void* temp = this;
        if(n == 0) return 0;
        return temp(n-1)+temp(n-2);
  }
};
0
struct func
{
  int operator()(int a)	{
  	if(a == 0) return 5;
  	else return (*this)(a - 1);
  }
};
0

Do wyboru do koloru:
1.

struct functor
  {
   int operator() (int n)
     {
      return n<2?n:operator()(n-1)+operator()(n-2);
     }
  };
struct functor
  {
   int operator() (int n)
     {
      return n<2?n:(*this)(n-1)+(*this)(n-2);
     }
  };
struct functor
  {
   int operator() (int n)
     {
      functor &f=*this;
      return n<2?n:f(n-1)+f(n-2);
     }
  };

1 użytkowników online, w tym zalogowanych: 0, gości: 1