fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
  5.  
  6. // Wichtig: MyClass darf nicht kopierbar sein, weil sie ihre Adresse in
  7. // einem Callback registriert!
  8. class MyClass
  9. {
  10. // "echter" Callback ist friend, damit er die private Methode aufrufen darf
  11. friend void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
  12.  
  13. public:
  14. MyClass()
  15. {
  16. AdsSyncAddDeviceNotificationReq( pAddr,
  17. ADSIGRP_SYM_VALBYHND,
  18. lHdlVar,
  19. &NotificationSettings,
  20. &my_callback,
  21. *reinterpret_cast<unsigned long*>( this ),
  22. &lHdlNotification);
  23. }
  24.  
  25. ~MyClass()
  26. {
  27. // Callback wieder austragen!
  28. }
  29.  
  30.  
  31. MyClass( MyClass const& other ) = delete;
  32. MyClass( MyClass&& other ) = delete;
  33.  
  34. MyClass& operator=( MyClass const& other ) = delete;
  35. MyClass& operator=( MyClass&& other ) = delete;
  36.  
  37.  
  38. private:
  39. void OnCallback( AmsAddr* addr, AdsNotificationHeader* header )
  40. {
  41. // tadaaa
  42. }
  43. };
  44.  
  45. void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
  46. {
  47. MyClass* instance = reinterpret_cast<MyClass*>( param );
  48. instance->OnCallback( addr, header );
  49. }
  50.  
  51. int main()
  52. {
  53. // your code goes here
  54. return 0;
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:19: error: variable or field ‘my_callback’ declared void
 void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                   ^~~~~~~
prog.cpp:4:19: error: ‘AmsAddr’ was not declared in this scope
prog.cpp:4:27: error: expected primary-expression before ‘,’ token
 void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                           ^
prog.cpp:4:29: error: ‘AdsNotificationHeader’ was not declared in this scope
 void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                             ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:4:51: error: expected primary-expression before ‘,’ token
 void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                                                   ^
prog.cpp:4:53: error: expected primary-expression before ‘unsigned’
 void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                                                     ^~~~~~~~
prog.cpp:11:27: error: ‘AmsAddr’ has not been declared
  friend void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                           ^~~~~~~
prog.cpp:11:37: error: ‘AdsNotificationHeader’ has not been declared
  friend void my_callback( AmsAddr*, AdsNotificationHeader*, unsigned long );
                                     ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:39:19: error: ‘AmsAddr’ has not been declared
  void OnCallback( AmsAddr* addr, AdsNotificationHeader* header )
                   ^~~~~~~
prog.cpp:39:34: error: ‘AdsNotificationHeader’ has not been declared
  void OnCallback( AmsAddr* addr, AdsNotificationHeader* header )
                                  ^~~~~~~~~~~~~~~~~~~~~
prog.cpp: In constructor ‘MyClass::MyClass()’:
prog.cpp:16:36: error: ‘pAddr’ was not declared in this scope
   AdsSyncAddDeviceNotificationReq( pAddr,
                                    ^~~~~
prog.cpp:17:12: error: ‘ADSIGRP_SYM_VALBYHND’ was not declared in this scope
            ADSIGRP_SYM_VALBYHND,
            ^~~~~~~~~~~~~~~~~~~~
prog.cpp:18:12: error: ‘lHdlVar’ was not declared in this scope
            lHdlVar,
            ^~~~~~~
prog.cpp:19:13: error: ‘NotificationSettings’ was not declared in this scope
            &NotificationSettings,
             ^~~~~~~~~~~~~~~~~~~~
prog.cpp:20:13: error: ‘my_callback’ was not declared in this scope
            &my_callback,
             ^~~~~~~~~~~
prog.cpp:22:13: error: ‘lHdlNotification’ was not declared in this scope
            &lHdlNotification);
             ^~~~~~~~~~~~~~~~
prog.cpp:16:3: error: ‘AdsSyncAddDeviceNotificationReq’ was not declared in this scope
   AdsSyncAddDeviceNotificationReq( pAddr,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp: At global scope:
prog.cpp:45:19: error: variable or field ‘my_callback’ declared void
 void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
                   ^~~~~~~
prog.cpp:45:19: error: ‘AmsAddr’ was not declared in this scope
prog.cpp:45:28: error: ‘addr’ was not declared in this scope
 void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
                            ^~~~
prog.cpp:45:34: error: ‘AdsNotificationHeader’ was not declared in this scope
 void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
                                  ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:45:57: error: ‘header’ was not declared in this scope
 void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
                                                         ^~~~~~
prog.cpp:45:65: error: expected primary-expression before ‘unsigned’
 void my_callback( AmsAddr* addr, AdsNotificationHeader* header, unsigned long param )
                                                                 ^~~~~~~~
stdout
Standard output is empty