You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
689 B

  1. #include <cstdio>
  2. #include <string>
  3. #include <tool/delegate.h>
  4. class MyClass
  5. {
  6. public:
  7. int MyMethod( const string& arg )
  8. {
  9. printf( "MyClass(this = %p)::MyMethod() called with string '%s', length %d\n", this,
  10. arg.c_str(), arg.length() );
  11. return arg.length();
  12. }
  13. };
  14. typedef DELEGATE<int, const string&> MyDelegate;
  15. main()
  16. {
  17. MyClass t1;
  18. MyClass t2;
  19. MyDelegate ptr1( &t1, &MyClass::MyMethod );
  20. MyDelegate ptr2( &t2, &MyClass::MyMethod );
  21. int retval1, retval2;
  22. retval1 = ptr1( "apples" );
  23. retval2 = ptr2( "cherries" );
  24. printf( "Object 1 returned %d, object 2 returned %d\n", retval1, retval2 );
  25. return 0;
  26. }