What does “return {}” statement mean in C++11?

后端 未结 4 490
广开言路
广开言路 2021-01-30 02:59

What does the statement

return {};

in C++11 indicate, and when to use it instead of (say)

return NULL;

or

4条回答
  •  無奈伤痛
    2021-01-30 03:28

    This is probably confusing:

    int foo()
    {
      return {};   // honestly, just return 0 - it's clearer
    }
    

    This is probably not:

    SomeObjectWithADefaultConstructor foo()
    {
      return {};
      // equivalent to return SomeObjectWithADefaultConstructor {};
    }
    

提交回复
热议问题