Pedia Pedia - 11 months ago 82
C++ Question

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

What does the statement

return {};


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

return NULL;


or

return nullptr;

Answer Source

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 {};
}