Pedia Pedia - 2 months ago 12
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

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