I\'m a C++ beginner and would like to understand why
return std::list();
needs parentheses, but
std::list
Both statements call default constructor.
return std::list();
This is same as:
std::list value;
return value;
Here an object is created (using default constructor) and object is returned.
std::list foo;
Here object foo
is created using the default constructor.
Here are other way to do the same in C++11
:
std::list foo;
std::list foo1{}; // C++11