Passing a bool as a param. C++

心已入冬 提交于 2019-12-02 14:24:16

You need to pass by reference, i.e.:

void setcat(bool& booltoset)
{
 booltoset = true; 
}

Any function argument is just a variable with scope identical to the function body. If it's an ordinary automatic variable, then changing it has not effect on the caller. This is sometimes useful: you can actually use the arguments, for example:

template<typename F>
void for_each(noexcept_it i, const noexcept_it end, const F &f) noexcept(noexcept(f))
{
   for(; i!=end; ++i) f(i);   // use i as iteration variable.
}

though the compiler will optimise such things anyway in most cases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!