fork download
  1. #include <iostream>
  2.  
  3. template <typename R, typename... Tn>
  4. class func
  5. {
  6. R (*fptr)(Tn...); // C2091
  7. public:
  8. func() : fptr(nullptr) {}
  9. func( R (*f) (Tn...) ) : fptr(f) {} // C2091
  10. R operator()(Tn... args)
  11. { // C2091
  12. return fptr(args...);
  13. }
  14. func& operator=( R (*f) (Tn...) ) // C2091
  15. {
  16. fptr = f;
  17. return *this;
  18. }
  19. };
  20.  
  21. int foo(int a, int b)
  22. {
  23. std::cout << "foo\n";
  24. return 0;
  25. }
  26.  
  27. int main()
  28. {
  29. func<int, int, int> myfunc;
  30. myfunc = foo; // C2679: binary '=' : no operator found which takes
  31. // a right-hand operand of type 'int (__cdecl *)(int,int)' (or
  32. // there is no acceptable conversion)
  33. return myfunc(1, 2);
  34. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
foo