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 saf
As a side-note on the presented code, I would instead templatize the void*
:
class Stuff
{
public:
template
static void print_number(const T& t)
{
std::cout << t.number;
}
int number;
Stuff(int number_)
: number(number_)
{
print_number(*this);
}
};
Then you'd get a compile error if the type of t
doesn't have a number
member.