C++ Lambda Expression recursive

Description

C++ Lambda Expression recursive

#include <iostream>
#include <functional>

int main()/*from  ww  w  .j  ava2s  .  c  o  m*/
{
  std::function<int(int)> reverseNumber {[&reverseNumber](int no) -> int
  {
        static int r {};
        if (0 == no)
              return r;
        else
              r = r * 10 + no % 10;
        return reverseNumber(no / 10);
  }};
  int nn {12345}, r {};
  std::cout << nn << "  " << reverseNumber(nn) << std::endl;
}



PreviousNext

Related