KiCad PCB EDA Suite
delegate_example.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <string>
3 
4 #include <tool/delegate.h>
5 
6 class MyClass
7 {
8 public:
9  int MyMethod( const string& arg )
10  {
11  printf( "MyClass(this = %p)::MyMethod() called with string '%s', length %d\n", this,
12  arg.c_str(), arg.length() );
13  return arg.length();
14  }
15 };
16 
17 typedef DELEGATE<int, const string&> MyDelegate;
18 
20 {
21  MyClass t1;
22  MyClass t2;
23 
24  MyDelegate ptr1( &t1, &MyClass::MyMethod );
25  MyDelegate ptr2( &t2, &MyClass::MyMethod );
26 
27  int retval1, retval2;
28 
29  retval1 = ptr1( "apples" );
30  retval2 = ptr2( "cherries" );
31 
32  printf( "Object 1 returned %d, object 2 returned %d\n", retval1, retval2 );
33  return 0;
34 }
main()
int MyMethod(const string &arg)
DELEGATE< int, const string & > MyDelegate