Advertisement
Guest User

Class method pointer

a guest
Apr 12th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class A {
  2. public:
  3.     float method1(float a) { does something with a}
  4. };
  5.  
  6. class B {
  7. public:
  8.     float method2(float a) { does something with a}
  9.     float anothermethod2(float a) { does something with a}
  10. };
  11.  
  12. class B {
  13. public:
  14.     float method3(float a) { does something with a}
  15. };
  16.  
  17. int main()
  18. {
  19.     A  a1;
  20.     B  b,b2;
  21.     C  c;
  22.  
  23.     std::vector< (what do i put in here?)> MethodsToCall;
  24.  
  25.     // put specific object's methods into the vector
  26.     MethodsToCall.pushback(  a1::method1 );
  27.     MethodsToCall.pushback(  b::method2 );
  28.     MethodsToCall.pushback(  c::method3 );
  29.     MethodsToCall.pushback(  b2::anothermethod2 );
  30.  
  31.     // call all the object's methods.
  32.     for(F : MethodsToCall )
  33.     {
  34.         std::cout << F(3.5) << std::endl;
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement