传递一个布尔值作为参数。 C ++ [英] Passing a bool as a param. C++
本文介绍了传递一个布尔值作为参数。 C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么,我要做的是下面一个例子。
what I am trying to do is an example below.
让我们首先定义一个布尔值。
let's first define a bool.
bool cat = {false};
可以做一个假布尔这里。
lets make a fake bool here.
bool setcat(bool booltoset)
{
booltoset = true;
return booltoset;
}
现在让猫来调用它。
printf("cat is %s", cat?"true":"false"); //set cat as false.
我的问题是;是否有可能实际上是通过一个参数传递一个布尔值比设置布尔?
my question is; is it possible to actually pass a bool through an argument than set that bool?
推荐答案
您需要通过参考,即通过:
You need to pass by reference, i.e.:
void setcat(bool& booltoset)
{
booltoset = true;
}
这篇关于传递一个布尔值作为参数。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文