Functor

#include <iostream>
#include <math.h>
using namespace std;

class Pow
{
   public:
      double operator()(double x, int y)
      {
     double xx = x;
for (int i = 0; i < y-1; i++) x *=xx; return x; } }; int main() { int a = 5; cout << pow(a, 2) << endl; Pow mypow; cout << "mypow:" << mypow(a, 2); return 0; }

 

   for (auto itr = vi.begin(); itr != vi.end(); ++itr)
   {
      cout << *itr << endl;
   }

 

for (auto i:vi)
{
   cout << i << endl;   
}

 

Guess you like

Origin www.cnblogs.com/aelite/p/11306579.html