Questions tagged «pointer-to-member»



5
什么是`int foo :: * bar :: *`?
C ++的一个很酷的功能是,它允许您创建指针到成员类型的变量。最常见的用例似乎是获取方法的指针: struct foo { int x() { return 5; } }; int (foo::*ptr)() = &foo::x; foo myFoo; cout << (myFoo.*ptr)() << '\n'; // prints "5" 但是,一团糟,我意识到它们也可以指向成员变量: struct foo { int y; }; int foo::*ptr = &foo::y; foo myFoo; myFoo.*ptr = 5; cout << myFoo.y << '\n'; // prints "5" …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.