gpt4 book ai didi

c++ - void 函数允许返回 "nothing"吗?

转载 作者:行者123 更新时间:2023-11-30 00:53:10 24 4
gpt4 key购买 nike

我很抱歉,但我仍在学习。并且请不要动我的名声:)这个编译,我只是想知道是否有更好的解决方案。我觉得它不是很优雅。If (Price==0) 我想什么都不做就退出函数。

void Esempio(int Price)
{
if (Price==0)
return;
MyArray[0]=Price;
}

这是退出 void 函数的正确方法吗?我指的是回归。我突然想到,我从未见过“什么都不返回”。还有什么更“优雅”的吗?

谢谢。

最佳答案

is this a correct way to exit a void function ?

是的,是的。

Anything more "elegant"

void Esempio(int Price)
{
if(Price != 0)
MyArray[0] = Price;
}

关于c++ - void 函数允许返回 "nothing"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17248576/

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