gpt4 book ai didi

c++ - cout 语句中首先运行的是什么? (C++17)

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:49 25 4
gpt4 key购买 nike

比如说我有一个很长的陈述

cout << findCurrent() << "," << findLowest() << "," << findHighest() << "," << findThird()<<"\n";

findCurrent()findLowest() 之前运行喜欢逻辑吗?

最佳答案

自 C++17 起,函数保证从左到右调用,即 findCurrent()首先被调用,然后是findLowest()等等。

C++17 标准引用:[expr.shift]/4(指表达式 E1 << E2):

The expression E1 is sequenced before the expression E2.

[over.match.oper]/2:(描述重载运算符)

the operands are sequenced in the order prescribed for the built-in operator.

[介绍.执行]/15:

An expression X is said to be sequenced before an expression Y if every value computation and every side effect associated with the expression X is sequenced before every value computation and every side effect associated with the expression Y.

Link to cppreference summary


在 C++17 之前,函数调用的顺序是未指定,这意味着它们可以以任何顺序调用(并且这个顺序在重复调用时不需要相同)。

关于c++ - cout 语句中首先运行的是什么? (C++17),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50361284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com