Why won’t this compile without a default constructor?

Clang gives this warning message: <source>:12:16: warning: parentheses were disambiguated as redundant parentheses around declaration of variable named ‘num’ [-Wvexing-parse] Boo(num); // No default constructor ^~~~~ This is a most-vexing parse issue. Because Boo is the name of a class type and num is not a type name, Boo(num); could be either the construction of … Read more

Why does C++ allow us to surround the variable name in parentheses when declaring a variable?

Grouping. As a particular example, consider that you can declare a variable of function type such as int f(int); Now, how would you declare a pointer to such a thing? int *f(int); Nope, doesn’t work! This is interpreted as a function returning int*. You need to add in the parentheses to make it parse the … Read more

Default constructor with empty brackets

Most vexing parse This is related to what is known as “C++’s most vexing parse”. Basically, anything that can be interpreted by the compiler as a function declaration will be interpreted as a function declaration. Another instance of the same problem: std::ifstream ifs(“file.txt”); std::vector<T> v(std::istream_iterator<T>(ifs), std::istream_iterator<T>()); v is interpreted as a declaration of function with … Read more