Is it safe to use the “this” pointer in an initialization list?
问题 I have two classes with a parent-child relationship (the Parent class "has-a" Child class), and the Child class has a pointer back to the Parent . It would be nice to initialize the parent pointer upon construction of the child, as follows: class Child; class Parent; class Child { public: Child (Parent* parent_ptr_) : parent_ptr(parent_ptr_) {}; private: Parent* parent_ptr; }; class Parent { public: Parent() : child(this) {}; private: Child child; } Now, I know people recommend not using this