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< int >::*v_vi_szt) (size_t); // v_vi_szt is used to hide the unwieldy syntaxv_vi_szt  reserve_ptr = &vector< int >::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< string >::*v_vs_szt) (size_t)  = &vector< string >::reserve; // string  specialization 
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: