【发布时间】:2015-01-03 20:49:13
【问题描述】:
如果我想验证赋值操作怎么办?
链接http://ideone.com/pVE40h
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
int p;
if (p = 2) // 1 case
cout << "assigned";
else
cout << "not assigned";
if(str = "my string") // 2 case
cout << "assigned"
else
cout << "not assigned";
return 0;
}
我的问题是,如果案例 1 有效,那么案例 2 应该有效,如果没有,为什么?应该这么简单? 我知道你们在这里发布的所有内容都在尝试捕捉东西,但我认为我应该那样工作??
【问题讨论】:
-
阅读参考资料。如果有问题就会抛出。
-
如果我想从头检查怎么办?
-
然后捕获异常,就像您可能能够处理的任何其他异常一样。
-
可能但不是好主意...
-
您可以验证分配,但谁来验证验证?