c++ - Does pointer-to-member make sense for a static member? -
the pointer-to-member feature of c++ interesting , powerful, i'm wondering if or should limited instantiated objects of class, or if okay point static member? use cases aren't obvious me either static or non-static usage of feature, though seem interesting.
pointers statics "normal" pointers, e.g.
class myclass { public: static int x; static int f(int a) { return a+1; } }; // ... int* pint = &myclass::x; // pointer static property int (*pfunc)(int) = &myclass::f; // pointer static method
pointers non-static members "special" because need class instance dereference value. can thought of "offset of member inside class instance" (this rough, though, , cannot applied method pointers!).
static members, on contrast, namespaced global variables, possibly restricted visibility. have static memory addresses, independent of class instances — instances share single static member.
Comments
Post a Comment