函数的最后一行放不放return有什么不同吗?
void InputClass::KeyDown(unsigned int input)
{
// If a key is pressed then save that state in the key array
m_keys[input] = true;
return;
}
最佳答案
不,没有区别!
void 函数中的return 用于在某些情况下提前退出。
例如:
void f(bool cond)
{
// do stuff here
if(cond)
return;
// do other stuff
}
关于c++ - void 函数中 return 的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18638286/