C++ C++;嵌入函数中的函数是否反向运行?

C++ C++;嵌入函数中的函数是否反向运行?,c++,function,reverse,C++,Function,Reverse,抱歉,如果这是个愚蠢的问题。我相信你们知道为什么会发生这种情况,但在我的(C++)函数代码中 int result = calculateResult(getUserInput1(), getMathematicalOperation() , getUserInput2()) 首先运行函数“getUserInput2()”而不是“getUserInput1()。当C++嵌入其他函数时,C++中的函数是否正常运行? 完整代码如下 // SimpleCalculator.cpp : Defines

抱歉,如果这是个愚蠢的问题。我相信你们知道为什么会发生这种情况,但在我的(C++)函数代码中

int result = calculateResult(getUserInput1(), getMathematicalOperation() , getUserInput2())
首先运行函数“getUserInput2()”而不是“getUserInput1()。当C++嵌入其他函数时,C++中的函数是否正常运行?

完整代码如下

// SimpleCalculator.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>

int getUserInput1()
{
    std::cout << "Please enter an integer 1: ";
    int value;
    std::cin >> value;
    return value;
}

int getUserInput2()
{
    std::cout << "Please enter an integer 2: ";
    int value;
    std::cin >> value;
    return value;
}

int getMathematicalOperation()
{
    std::cout << "Please enter the operator you wish to use (1 = +, 2 = -, 3 = *, 4 = /): ";
    int op;
    std::cin >> op;

    std::cout << "the operator number you chose is : " << std::endl << op << std::endl;

    return op;
}

int calculateResult(int x, int op, int y)
{
    if (op == 1)
        return x + y;
    if (op == 2)
        return x - y;
    if (op == 3)
        return x * y;
    if (op == 4)
        return x / y;

    return -1;
}

void printResult(int result)
{
    std::cout << "Your result is : " << result << std::endl;
}
//SimpleCalculator.cpp:定义控制台应用程序的入口点。
//
#包括“stdafx.h”
#包括
int getUserInput1()
{
标准::cout>值;
返回值;
}
int getUserInput2()
{
标准::cout>值;
返回值;
}
int getMathematicalOperation()
{
std::cout>op;

是的,这是正常的。

严格地说,评估顺序是未指定的,这是该规则的常见结果

这可能看起来有点愚蠢,但我认为这很好,因为它确实让人明白,你不应该依赖任何特定的顺序,尤其是你最初可能假设的最左边的第一个顺序


如果需要特定的评估顺序,请先将调用结果存储在变量中。是的,这是正常的。

严格地说,评估顺序是未指定的,这是该规则的常见结果

这可能看起来有点愚蠢,但我认为这很好,因为它确实让人明白,你不应该依赖任何特定的顺序,尤其是你最初可能假设的最左边的第一个顺序


如果您需要特定的求值顺序,请先将调用结果存储在变量中。

参数的求值顺序未指定,您永远不应该依赖任何特定的求值顺序。参数的求值顺序未指定,您永远不应该依赖任何特定的求值顺序。我最初是这样做的,但我正在尝试实践ice看到我如何缩短代码,因此发生了上述情况。这确实表明我在假设时需要小心。我最初是这样做的,但我试图通过看到我如何缩短代码,从而发生上述情况来进行练习。这确实表明我在假设时需要小心。