struct test
{
void f() {};
};
test t1;
using memfun_t = void (test::*)();
memfun_t mf = &test::f;
auto a1 = &test::f; // OK
auto a2 = t1.*mf; // error
auto a3 = &(t1.*mf); // still no
include <stdio.h>
class Base
{
protected:
int foo;
int get_foo() { return foo; }
};
class Derived : public Base
{
public:
void bar()
{
int Base::* i = &Base::foo;
//#define NOT_WORKS
#define HOW(X) 0
struct A {
};
struct B {
A a;
};
struct C {
B b;
};
int main(int argc, char **argv) {
A B::*ba = &B::a; // ba is a pointer to B::a mem
假設我有這樣的代碼: #include <iostream>
struct Mine
{
int a;
int b;
};
int main()
{
int Mine::* memberPointerA = &Mine::a;
int Mine::* memberPointerB = &Mine::b;
std::cout
嗨我想弄清楚是否合法(由C++)標準來計算類的成員的偏移量(爲了扭轉它)。 class A
{
public:
int a, b, c, d;
};
template <typename ParentClass, typename T>
ParentClass const * offset_this_pointer(T const * member_ptr, T Parent