fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm> // std::remove_if
  4. using namespace std;
  5.  
  6. template <typename T>
  7. class check {
  8. public:
  9. virtual bool operator()(T x) = 0;
  10.  
  11. struct aid{
  12. aid(check *p){ _c = p;}
  13. check *_c;
  14. bool operator()(T x){
  15. return _c->operator ()(x);
  16. }
  17. };
  18.  
  19. aid retMe(){
  20. return aid(this);
  21. }
  22. };
  23.  
  24. int main() {
  25.  
  26. int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  27. std::vector<int> v( array, array+10 );
  28.  
  29. class even : public check<int>
  30. {
  31. public:
  32. virtual bool operator()( int x ) { cout<<"Hi"<<endl; return !( x % 2 ); }
  33. };
  34. even e;
  35.  
  36. remove_if( v.begin(), v.end(), e.retMe()); // no error
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi