#include <iostream>
#include <vector>
struct S {
//std::vector<int> ns(1); //ERROR!
std::vector<int> ns = std::vector<int>(1);
};
int main() {
S s;
std::cout << (s.ns[0] = 123) << std::endl;
return 0;
}
Using the parentheses initializer seems to be an error. What is the purpose behind this.
The idea is to flat out reject any syntax that could be interpreted as a function declaration. For example,
std::vector<int> ns();
is a function declaration. These aren't:
std::vector<int> ns{};
std::vector<int> ns = std::vector<int>();
For consistency, any member declaration with this form
T t(args...);
is disallowed, which avoids a repeat of the most vexing parse fiasco.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With