c++ - Complicated test to check which object instantiates a function call -
i have struct ( can class ) , defined in class shown
struct a{ somedata_a; somespecificimplementation_a(someclass *s1); }; class someclass{ somedata_someclass; a; }; main(){ someclass c1, *c2; c2 = &c1; c1.a.somespecificimplementation_a(c2); }
how verify c2 indeed reference c1? pardon me putting example obvious c2 reference c1.
update: not store pointer someclass
if don't know nothing parent, compare member' adresses
void a::somespecificimplementation_a(someclass *s1) { if (this == &(s1->a)) { // parent == s1 } else { // parent != s1 } }
Comments
Post a Comment