fork(2) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <memory>
  4. using namespace std;
  5.  
  6. struct connection;
  7. struct login;
  8. struct huin;
  9.  
  10. typedef shared_ptr<connection> connection_ptr;
  11. typedef shared_ptr<login> login_ptr;
  12. typedef shared_ptr<huin> huin_ptr;
  13.  
  14.  
  15. void on_message(const connection_ptr& , const login_ptr message ) {
  16. }
  17.  
  18. void on_message(const connection_ptr& , const huin_ptr message ) {
  19. }
  20.  
  21.  
  22. template<class T>
  23. void register_yoba( const function<void(const connection_ptr&, const shared_ptr<T>)> f ) {
  24.  
  25.  
  26. }
  27.  
  28.  
  29. int main() {
  30. register_yoba<login>(&on_message);
  31. register_yoba<huin>(&on_message);
  32. return 0;
  33. }
Compilation error #stdin compilation error #stdout 0s 4380KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:30:34: error: no matching function for call to ‘register_yoba<login>(<unresolved overloaded function type>)’
  register_yoba<login>(&on_message);
                                  ^
prog.cpp:23:6: note: candidate: ‘template<class T> void register_yoba(std::function<void(const std::shared_ptr<connection>&, std::shared_ptr<_Tp>)>)’
 void register_yoba( const function<void(const connection_ptr&, const shared_ptr<T>)> f ) {
      ^~~~~~~~~~~~~
prog.cpp:23:6: note:   template argument deduction/substitution failed:
prog.cpp:30:23: note:   cannot convert ‘& on_message’ (type ‘<unresolved overloaded function type>’) to type ‘std::function<void(const std::shared_ptr<connection>&, std::shared_ptr<login>)>’
  register_yoba<login>(&on_message);
                       ^~~~~~~~~~~
prog.cpp:31:33: error: no matching function for call to ‘register_yoba<huin>(<unresolved overloaded function type>)’
  register_yoba<huin>(&on_message);
                                 ^
prog.cpp:23:6: note: candidate: ‘template<class T> void register_yoba(std::function<void(const std::shared_ptr<connection>&, std::shared_ptr<_Tp>)>)’
 void register_yoba( const function<void(const connection_ptr&, const shared_ptr<T>)> f ) {
      ^~~~~~~~~~~~~
prog.cpp:23:6: note:   template argument deduction/substitution failed:
prog.cpp:31:22: note:   cannot convert ‘& on_message’ (type ‘<unresolved overloaded function type>’) to type ‘std::function<void(const std::shared_ptr<connection>&, std::shared_ptr<huin>)>’
  register_yoba<huin>(&on_message);
                      ^~~~~~~~~~~
stdout
Standard output is empty