Passing “this” to a function from within a constructor?
问题 Can I pass "this" to a function as a pointer, from within the class constructor, and use it to point at the object's members before the constructor returns? Is it safe to do this, so long as the accessed members are properly initialized before the function call? As an example: #include <iostream> class Stuff { public: static void print_number(void *param) { std::cout << reinterpret_cast<Stuff*>(param)->number; } int number; Stuff(int number_) : number(number_) { print_number(this); } }; void