summaryrefslogtreecommitdiff
path: root/include/tool/examples/delegate_example.cpp
diff options
context:
space:
mode:
authorsaurabhb172020-02-26 16:20:48 +0530
committerGitHub2020-02-26 16:20:48 +0530
commitb77f5d9d8097c38159c6f60917995d6af13bbe1c (patch)
tree1392c90227aeea231c1d86371131e04c40382918 /include/tool/examples/delegate_example.cpp
parentdadc4d490966a24efe15b5cc533ef8695986048a (diff)
parent003d02608917e7a69d1a98438837e94ccf68352a (diff)
downloadKiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.tar.gz
KiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.tar.bz2
KiCad-eSim-b77f5d9d8097c38159c6f60917995d6af13bbe1c.zip
Merge pull request #4 from FOSSEE/develop
merging dev into master
Diffstat (limited to 'include/tool/examples/delegate_example.cpp')
-rw-r--r--include/tool/examples/delegate_example.cpp34
1 files changed, 34 insertions, 0 deletions
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 <cstdio>
+#include <string>
+
+#include <tool/delegate.h>
+
+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<int, const string&> 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;
+}