2013-08-02 14:50:29 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <tool/delegate.h>
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
class MyClass
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int MyMethod( const string& arg )
|
|
|
|
{
|
|
|
|
printf( "MyClass(this = %p)::MyMethod() called with string '%s', length %d\n", this,
|
|
|
|
arg.c_str(), arg.length() );
|
|
|
|
return arg.length();
|
|
|
|
}
|
2013-08-02 14:50:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef DELEGATE<int, const string&> MyDelegate;
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
MyClass t1;
|
|
|
|
MyClass t2;
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
MyDelegate ptr1( &t1, &MyClass::MyMethod );
|
|
|
|
MyDelegate ptr2( &t2, &MyClass::MyMethod );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
int retval1, retval2;
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
retval1 = ptr1( "apples" );
|
|
|
|
retval2 = ptr2( "cherries" );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
printf( "Object 1 returned %d, object 2 returned %d\n", retval1, retval2 );
|
|
|
|
return 0;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|