Returning From a Void Function in C++

2020-02-26 07:19发布

Consider the following snippet:

void Foo()
{
  // ...
}

void Bar()
{
  return Foo();
}

What is a legitimate reason to use the above in C++ as opposed to the more common approach:

void Foo()
{
  // ...
}

void Bar()
{
  Foo();

  // no more expressions -- i.e., implicit return here
}

标签: c++ return void
7条回答
劫难
2楼-- · 2020-02-26 08:13

Could be a case where Foo() originally returned a value, but was later changed to void, and the person who updated it just didn't think very clearly.

查看更多
登录 后发表回答