M
mk
In C++ one can get an absolute address of data member, having a
pointer-to-member and a pointer to class object:
struct A
{
int m;
};
void f(A *a)
{
int A::*b = &A::m;
int *c = &(a->*b); // address-wise: c = a + b
}
Unfortunetly it seems that inverse operation, that is getting a
pointer to class object having pointer-to-member and absolute pointer
to member is impossible in a standard C++ program. This is a well
defined, simple operation that could be used this way:
void f(int *c)
{
int A::*b = &A::m;
A *a = /* what to put here? */ // address-wise: a = c - b;
}
Is there anything standard-compliant that I can put in place of
comment?
cheers,
Marcin Kalicinski
pointer-to-member and a pointer to class object:
struct A
{
int m;
};
void f(A *a)
{
int A::*b = &A::m;
int *c = &(a->*b); // address-wise: c = a + b
}
Unfortunetly it seems that inverse operation, that is getting a
pointer to class object having pointer-to-member and absolute pointer
to member is impossible in a standard C++ program. This is a well
defined, simple operation that could be used this way:
void f(int *c)
{
int A::*b = &A::m;
A *a = /* what to put here? */ // address-wise: a = c - b;
}
Is there anything standard-compliant that I can put in place of
comment?
cheers,
Marcin Kalicinski