3 ms·
It has the same syntax as JavaScript, but unfortunately C++ is quite a different language. As C++ has neither compiler check for lifetimes nor garbage collecti
by w-m 8y ago
It has the same syntax as JavaScript, but unfortunately C++ is quite a different language. As C++ has neither compiler check for lifetimes nor garbage collection, this would be very easy to misuse in practice.
The Timer requires anything captured by the lambda to still be alive by the time the function is called. This may be obvious in C++, but it's still dangerous.
Even trying to use this as a set-and-forget-timer without any captures to work around this gotcha (like the example just printing stuff) won't work as the Timer object itself also needs to stay alive until the function is called. Do it further down the stack and the Timer is long destroyed when its function is supposed to run.
- BagOfPistchios 8y agoagreed, it is dangeorus if newbies try to use this
- pjmlp 8y agoIf it was only newbies doing such kind of errors. :\