using namespace std; using namespace std::tr1; template <typename T1> class Event { protected: vector<function<void(T1)>> functors; vector<Event<T1>*> events; public: const static int ExpectedFunctorCount = 2; Event () : functors(), events() { functors.reserve( ExpectedFunctorCount ); events.reserve( ExpectedFunctorCount ); } void Add ( void(* func)( T1 ) ) { functors.push_back( function<void(T1)>( func ) ); } void Add ( function<void( T1 )> func ) { functors.push_back( func ); } void Invoke ( T1 a1 ) { for ( std::size_t f = 0; f < functors.size(); ++f ) { functors[f]( a1 ); } for ( std::size_t f = 0; f < events.size(); ++f ) { (*events[f])( a1 ); } } void operator() ( T1 a1 ) { Invoke( a1 ); } size_t InvocationCount ( ) { return events.size( ) + functors.size( ); } void RemoveAt ( size_t index ) { } }; template <> class Event<void> { protected: std::vector<function<void(void)>> functors; std::vector<Event<void>*> events; public: const static int ExpectedFunctorCount = 2; Event () : functors(), events() { functors.reserve( ExpectedFunctorCount ); events.reserve( ExpectedFunctorCount ); } void Add ( void(* func)( void ) ) { functors.push_back( function<void(void)>( func ) ); } void Add ( function<void( void )> func ) { functors.push_back( func ); } void Invoke ( void ) { for ( size_t f = 0; f < functors.size(); ++f ) { functors[f]( ); } for ( size_t f = 0; f < events.size(); ++f ) { (*events[f])( ); } } void operator() ( void ) { Invoke( ); } size_t InvocationCount ( ) { return events.size( ) + functors.size( ); } void RemoveAt ( size_t index ) { } }; void VoidTest () { cout << "INTO THE VOID" << endl; } void IntTest ( int num ) { cout << "Got myself a " << num << " !" << endl; } int main ( int argc, char* argv[] ) { Event<void> VoidEv; Event<int> IntEv; IntEv.Add( IntTest ); IntEv( 20 ); return 0; }
Events, go go!
prog.cpp:2:22: error: 'tr1' is not a namespace-name prog.cpp:2:25: error: expected namespace-name before ';' token prog.cpp:6:5: error: 'vector' does not name a type prog.cpp:7:2: error: 'vector' does not name a type prog.cpp:21:13: error: 'function' has not been declared prog.cpp:21:21: error: expected ',' or '...' before '<' token prog.cpp:38:2: error: 'size_t' does not name a type prog.cpp:42:18: error: 'size_t' has not been declared prog.cpp: In constructor 'Event<T1>::Event()': prog.cpp:12:13: error: class 'Event<T1>' does not have any field named 'functors' prog.cpp:12:25: error: class 'Event<T1>' does not have any field named 'events' prog.cpp:13:3: error: 'functors' was not declared in this scope prog.cpp:14:3: error: 'events' was not declared in this scope prog.cpp: In member function 'void Event<T1>::Add(void (*)(T1))': prog.cpp:18:3: error: 'functors' was not declared in this scope prog.cpp:18:23: error: 'function' was not declared in this scope prog.cpp:18:32: error: expected primary-expression before 'void' prog.cpp: In member function 'void Event<T1>::Add(int)': prog.cpp:22:3: error: 'functors' was not declared in this scope prog.cpp:22:23: error: 'func' was not declared in this scope prog.cpp: In member function 'void Event<T1>::Invoke(T1)': prog.cpp:26:9: error: 'size_t' is not a member of 'std' prog.cpp:26:21: error: expected ';' before 'f' prog.cpp:26:28: error: 'f' was not declared in this scope prog.cpp:26:32: error: 'functors' was not declared in this scope prog.cpp:29:9: error: 'size_t' is not a member of 'std' prog.cpp:29:21: error: expected ';' before 'f' prog.cpp:29:28: error: 'f' was not declared in this scope prog.cpp:29:32: error: 'events' was not declared in this scope prog.cpp: At global scope: prog.cpp:50:2: error: 'vector' in namespace 'std' does not name a type prog.cpp:51:2: error: 'vector' in namespace 'std' does not name a type prog.cpp:65:13: error: 'function' has not been declared prog.cpp:65:21: error: expected ',' or '...' before '<' token prog.cpp:82:2: error: 'size_t' does not name a type prog.cpp:86:18: error: 'size_t' has not been declared prog.cpp: In constructor 'Event<void>::Event()': prog.cpp:56:13: error: class 'Event<void>' does not have any field named 'functors' prog.cpp:56:25: error: class 'Event<void>' does not have any field named 'events' prog.cpp:57:3: error: 'functors' was not declared in this scope prog.cpp:58:3: error: 'events' was not declared in this scope prog.cpp: In member function 'void Event<void>::Add(void (*)())': prog.cpp:62:3: error: 'functors' was not declared in this scope prog.cpp:62:23: error: 'function' was not declared in this scope prog.cpp:62:32: error: expected primary-expression before 'void' prog.cpp: In member function 'void Event<void>::Add(int)': prog.cpp:66:3: error: 'functors' was not declared in this scope prog.cpp:66:23: error: 'func' was not declared in this scope prog.cpp: In member function 'void Event<void>::Invoke()': prog.cpp:70:9: error: 'size_t' was not declared in this scope prog.cpp:70:16: error: expected ';' before 'f' prog.cpp:70:23: error: 'f' was not declared in this scope prog.cpp:70:27: error: 'functors' was not declared in this scope prog.cpp:73:16: error: expected ';' before 'f' prog.cpp:73:23: error: 'f' was not declared in this scope prog.cpp:73:27: error: 'events' was not declared in this scope prog.cpp: In function 'void VoidTest()': prog.cpp:93:2: error: 'cout' was not declared in this scope prog.cpp:93:29: error: 'endl' was not declared in this scope prog.cpp: In function 'void IntTest(int)': prog.cpp:97:2: error: 'cout' was not declared in this scope prog.cpp:97:44: error: 'endl' was not declared in this scope
Standard output is empty