Consider the following code:
#include <thread>
struct S {
S() {
std::thread t(&S::bar, *this);
t.join();
}
void bar() {
// Do stuff...
}
};
int main() {
S s;
}
Is this code legal? Note that we call a member function on *this
, although the constructor has not yet run to the end. Does the situation change if we make bar
virtual?
virtual void bar() {
Is the behaviour of bar
in this case the same as here?
Please note that I only care if the standard defines this, I know that it's most likely considered bad practice by most.