21.6. Pointers to Class Members (.* and ->*)

C++ provides the .* and ->* operators for accessing class members via pointers. This is a rarely used capability, primarily for advanced C++ programmers. We provide only a mechanical example of using pointers to class members here. Figure 21.6 demonstrates the pointer-to-class-member operators.

 1   // Fig. 21.6: fig21_06.cpp 2   // Demonstrating operators .* and ->*. 3   #include <iostream> 4   using namespace std; 5  6   // class Test definition 7   class Test 8   { 9   public:10      void func()11      {12         cout << "In func\n";13      } // end function func14 15      int value; // public data member16   }; // end class Test17 18   void arrowStar( Test * ); ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.