Pointers to Members of a Template Class

Pointers to Members of a Template Class

You can define a pointer to a class template member. For example, you can use the specialization vector:

 	typedef void (vector::*v_vi_szt) (size_t); // v_vi_szt is used to hide the unwieldy syntaxv_vi_szt  reserve_ptr = &vector::reserve; 

The only difference from ordinary pointers to class members is that you are required to use a template specialization, since a template name per se is not a type. In other words, you have to define a separate pointer to member for every specialization used. In the following example, vector specialization is used (no typedef applied in this case):

 void (vector::*v_vs_szt) (size_t)  = &vector::reserve; // string  specialization 


Share the Post: