devxlogo

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< 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 
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist