fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8. using namespace std::placeholders;
  9.  
  10. class CPrueba
  11. {
  12. public:
  13. CPrueba(int x, int y):m_X(x), m_Y(y){ }
  14. int X()const {return m_X;}
  15. int Y()const {return m_Y;}
  16. private:
  17. int m_X;
  18. int m_Y;
  19. };
  20.  
  21. class ITest
  22. {
  23. public:
  24. virtual CPrueba Prueba(double p, double d = 0)const = 0;
  25. };
  26.  
  27. class CTest : public ITest
  28. {
  29. public:
  30. CTest(){}
  31.  
  32. CPrueba Prueba(double p, double d = 0)const{ return CPrueba(p, d); }
  33. };
  34.  
  35. void foo( ITest* test)
  36. {
  37. std::vector<double> v;
  38. v.push_back(10.0);
  39. v.push_back(20.0);
  40. v.push_back(30.0);
  41. v.push_back(40.0);
  42.  
  43. std::vector<CPrueba> vRes;
  44.  
  45. std::transform(v.begin(), v.end(), back_inserter(vRes), bind(&ITest::Prueba, test, _1, 0));
  46.  
  47. for(std::vector<CPrueba>::const_iterator it = vRes.begin(); it != vRes.end(); ++it)
  48. {
  49. cout << it->X() << "," << it->Y()<<endl;
  50. }
  51. }
  52.  
  53. int main() {
  54. CTest test;
  55.  
  56. foo(&test);
  57. return 0;
  58. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
10,0
20,0
30,0
40,0