Tuesday, 2 July 2013

can we create pointer to a memberfunction | pointer to a memberfunction


yes, we can create pointer to a memberfunction ;
example:-

          class sample
          {
               public:
                 
                      void fun()
                       {
                              cout << "function with pointer";
                       }
          };
     
           
        void(sample::*pfun)() = &sample::fun;
     
       void main()
        {
                   sample s;
                   (s, *pfun)();
        }

       here, pfun is a pinter to member function fun() of the class sample
            

0 comments:

Post a Comment