more headachy c++ gubbish.
Jul. 17th, 2008 05:30 pmIn C you can totally do this.
typedef struct { ... } S;
typedef struct { ...; S s; ... } T;
/* ESS assumed to be contained in a T. */
T * TfromS(S * ess) {
return (T *)(((char *)ess) - offsetof(T, s));
}
But in C++, offsetof is not defined when its first argument is a “non-POD type” (approximately, “a type you couldn't have declared in C.”) The replacement for offsetof is the “pointer to member.”
But you can't do the above with a pointer to member.
So how the Belgium do you do it?