Pointers to class / struct members
suggest changeSyntax
Assuming a class named Class
:
type *ptr = &Class::member;
// Point to static members onlytype Class::*ptr = &Class::member;
// Point to non-static Class members
For pointers to non-static class members, given the following two definitions:
Class instance;
Class *p = &instance;
Pointers to Class member variables
ptr = &Class::i;
// Point to variable i within every Classinstance.*ptr = 1;
// Access instance’s ip->*ptr = 1;
// Access p’s i
Pointers to Class member functions
ptr = &Class::F;
// Point to function ‘F’ within every Class(instance.*ptr)(5);
// Call instance’s F(p->*ptr)(6);
// Call p’s F
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents