以下 2 个代码片段之间是否有任何功能差异
Is there any functional difference between the following 2 code snippets?
以下 2 个代码片段之间有什么功能差异吗?
bool ColorClass::setTo(int inRed, int inGreen, int inBlue)
{
amountRed = inRed;
amountGreen = inGreen;
amountBlue = inBlue;
return clipColor(amountRed, amountGreen, amountBlue);
}
bool ColorClass::setTo(int inRed, int inGreen, int inBlue)
{
amountRed = inRed;
amountGreen = inGreen;
amountBlue = inBlue;
if (clipColor(amountRed, amountGreen, amountBlue))
{
return true;
}
else
{
return false;
}
}
上述代码调用的函数定义如下:
bool ColorClass::clipColor(int &checkRed, int &checkGreen, int &checkBlue)
{
int numClips = 0; //numClips is used to counter number of clips made
checkColorBounds(checkRed, numClips);
checkColorBounds(checkGreen, numClips );
checkColorBounds(checkBlue, numClips);
return (numClips != 0);
}
void ColorClass::checkColorBounds(int &color, int &clipCounter)
{
if(color > MAXCOLOR)
{
color = MAXCOLOR;
clipCounter++;
}
else if (color < MINCOLOR)
{
color = MINCOLOR;
clipCounter ++;
}
}
我测试了两者并经历了两者,我似乎没有注意到任何功能上的差异。
我更喜欢第一个,因为它更简洁,更高效(避免if-else(
完全没有任何功能差异。然后使用第一个。
吻
相关文章:
- 是否有任何C++功能可以对地图进行排序?
- RtMidi - MidiInDummy:此类不提供任何功能
- 是否有任何模式等效于虚拟模板功能?
- 是否有任何功能可以通过按不同的按钮来更改操作
- C 中的余弦功能,没有任何数学功能
- 如何子类可运行任何成员功能
- 构造函数超载以接受任何功能
- 任何操作员,功能调用和构造函数的通用持续时间表
- 任何挂钩功能的单一接口
- 我可以使用QT的OpenGL功能而没有任何小部件
- C 库中是否有任何功能将字符串转换为算术操作
- 可用于任何大小的数组的功能
- C 模板功能是否有任何方法可以采用n个参数
- c++ 是否允许在任何功能之外调用函数?
- LDAP函数中是否有任何功能可以在不使用ldap_search的情况下获取用户信息
- C 模板类包装任何功能
- 如何使用C 在Arduino上制作LED闪光灯,但除了Millis()之外,没有使用任何功能
- 我想知道是否有任何功能或方法可以首先检查文件是否已创建
- 以下 2 个代码片段之间是否有任何功能差异
- C或C++或WinApi中是否有任何功能来创建目录,包括指定路径中所有不存在的目录