<分区>
我必须使用 if 语句检查 3 种方法的结果。如果方法 1 为真,那么我只需要调用方法 2,如果方法 2 为真,那么我只需要调用方法 3。目前我正在为此目的使用以下代码。
if(method1())
{
if(method2())
{
if(method3())
{
cout << "succeeded";
}
else
{
cout << "failed";
}
}
else
{
cout << "failed";
}
}
else
{
cout << "failed";
}
我只想使用一个 if 语句并调用其中的所有 3 个方法。所以我正在考虑以下方式。下面的代码会和上面的代码一样工作还是会有所不同?
if(method1() && method2() && method3())
{
cout << "succeeded";
}
else
{
cout << "failed";
}