| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 
 | #include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
 
typedef std::tr1::function< void (int)> TestFunction;
 
class Test
{
public:
 
 
	void testA( int a )
	{
		std::cout << "TEST A" << std::endl;
	}
 
	void testB( int b )
	{
		std::cout << "TEST B" << std::endl;
	}
 
	void registerFunction( std::vector< TestFunction >& functionList )
	{
		TestFunction functionA( std::bind1st( std::mem_fun( &Test::testA ) , this ) ) ;
		functionList.push_back( functionA );
		TestFunction functionB( std::bind1st( std::mem_fun( &Test::testB ) , this ) ) ;
		functionList.push_back( functionB );
	}
 
};
 
void testMachin( int k )
{
	std::cout << "Test MACHIN" << std::endl;
}
 
int main()
{
	Test test;
 
	std::vector< TestFunction > functionList;
	functionList.push_back( &testMachin );
 
	test.registerFunction( functionList );
 
	if( std::find( functionList.begin(), functionList.end(), &testMachin ) != functionList.end() )
	{
		std::cout << "Test machin is in the place!" << std::endl;
	}
 
	for( unsigned int i = 0; i < functionList.size(); ++i )
	{
		functionList[ i ]( i );
	}
 
	std::system( "pause" );
 
 
} | 
Partager