educative.io

Educative

Can compile your example?

Hi,
is your example correct? I think that it cannot compile:

"
struct Sleeper{
Sleeper(int& i_):i{i_}{};
void operator() (int k) {
for (unsigned int j = 0; j <= 5; ++j) {
sleep_for(std::chrono::milliseconds(100));
i += k;
}
std::cout << get_id();
<======== A claudator is needed here?
private:
int& i;
};
int valSleeper= 1000;
// undefined behaviour
} <============= ???
std::thread t(Sleeper(valSleeper), 5);
t.detach();
std::cout << valSleeper; // undefined behaviour
"

Did you left a claudator in your sleeper struct?
What does the last claudator?