In the example with threads, I met a parameter passing through the ref function from the standard library, it is not clear how to use it, why can't the variable be passed just by its name?
Here is the actual example:
#include <iostream> #include <thread> void threadFunction(int &a) { a++; } int main() { int a = 1; std::thread thr(threadFunction, std::ref(a)); // что делает функция ref()? почему нельзя передовать просто переменную по ее имени? thr.join(); std::cout << a << std::endl; return 0; } added later
when passing simply by the name std :: thread thr (threadFunction, a); the program does not compile and crashes
