From 039ac92480a09266146fc5b0c9ec67a32a2565ad Mon Sep 17 00:00:00 2001 From: saurabhb17 Date: Wed, 26 Feb 2020 16:04:40 +0530 Subject: Added secondary files --- include/tool/examples/delegate_example.cpp | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 include/tool/examples/delegate_example.cpp (limited to 'include/tool/examples/delegate_example.cpp') diff --git a/include/tool/examples/delegate_example.cpp b/include/tool/examples/delegate_example.cpp new file mode 100644 index 0000000..3d3c782 --- /dev/null +++ b/include/tool/examples/delegate_example.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include + +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(); + } +}; + +typedef DELEGATE MyDelegate; + +main() +{ + MyClass t1; + MyClass t2; + + MyDelegate ptr1( &t1, &MyClass::MyMethod ); + MyDelegate ptr2( &t2, &MyClass::MyMethod ); + + int retval1, retval2; + + retval1 = ptr1( "apples" ); + retval2 = ptr2( "cherries" ); + + printf( "Object 1 returned %d, object 2 returned %d\n", retval1, retval2 ); + return 0; +} -- cgit