fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct Bar {
  5. int z;
  6.  
  7. Bar(int z) : z(z) {}
  8.  
  9. void add(int x, int y) { std::cout << x + y + z << std::endl; }
  10. };
  11.  
  12. template <typename T, typename... Arguments>
  13. struct Foo {
  14. std::function<void(T&, Arguments ...)> f;
  15.  
  16. template <typename F> Foo(F&& f) : f(std::forward<F>(f)) {}
  17.  
  18. void execute(Arguments ... args) {
  19. T c(2);
  20. f(c, args ...);
  21. }
  22. };
  23.  
  24. int main() {
  25. auto b = Foo<Bar, int, int>(&Bar::add);
  26. b.execute(4, 5);
  27.  
  28. return 0;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: stray ‘\177’ in program
prog.cpp:1:1: error: stray ‘#’ in program
prog.cpp:1:3: error: ‘include’ does not name a type
prog.cpp: In member function ‘void Bar::add(int, int)’:
prog.cpp:9:27: error: ‘cout’ is not a member of ‘std’
prog.cpp:9:53: error: ‘endl’ is not a member of ‘std’
prog.cpp: At global scope:
prog.cpp:12:31: warning: variadic templates only available with -std=c++11 or -std=gnu++11 [enabled by default]
prog.cpp:14:2: error: ‘function’ in namespace ‘std’ does not name a type
prog.cpp:16:29: error: expected ‘,’ or ‘...’ before ‘&&’ token
prog.cpp:18:29: warning: variadic templates only available with -std=c++11 or -std=gnu++11 [enabled by default]
prog.cpp: In constructor ‘Foo<T, Arguments>::Foo(F)’:
prog.cpp:16:37: error: class ‘Foo<T, Arguments>’ does not have any field named ‘f’
prog.cpp:16:39: error: ‘forward’ is not a member of ‘std’
prog.cpp:16:53: error: expected primary-expression before ‘>’ token
prog.cpp:16:55: error: ‘f’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp:25:2: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
prog.cpp:25:7: error: ‘b’ does not name a type
prog.cpp:26:2: error: ‘b’ was not declared in this scope
stdout
Standard output is empty