C++ Logo

std-discussion

Advanced search

Fwd: Parent pointer to access the parent class from member

From: Hanspeter Bieri-Ineichen <bieri.hp_at_[hidden]>
Date: Mon, 29 Jun 2020 00:17:48 +0200
The important ability of C/C++ that classes can be direct members of a
class allows to access them by a this-pointer offset instead of a pointer
derefenciation.

To access the parent class from a member the usual way is to store a
pointer to the parent. There no simple way that uses the member offset. A
template solution is shown here:
https://stackoverflow.com/questions/62103638/access-parent-class-from-member-without-storing-pointer-of-parent


Would it be useful to have something like a parent pointer similar to the
this-pointer?

Received on 2020-06-28 17:21:12