【发布时间】:2019-08-11 19:17:42
【问题描述】:
有人可以向我解释这里发生了什么吗?
#include <iostream>
using namespace std;
int main() {
bool x = false;
if (x = true) { cout << "x is true" << endl; }
if (x = false) { cout << "x is false" << endl; }
// for some reason always prints "x is true".
}
我试图弄清楚为什么我不能使用布尔方法进行引用调用(是的,我也在擦除该方法后进行了测试),然后我意识到我的主要方法中的布尔变量正在改变在其自己的。请帮忙!
【问题讨论】:
标签: c++ variables boolean pass-by-reference main