Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: Advanced
Nov 19, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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<int>:
typedef void (vector< int >::*v_vi_szt) (size_t); // v_vi_szt is used to hide the unwieldy syntax
v_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 <string> specialization is used (no typedef applied in this case):
void (vector< string >::*v_vs_szt) (size_t)  = &vector< string >::reserve; // string  specialization 
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date