3 ms·
Output is: vector<int> v{3} size() 1 vector<string> v{3} size() 3 vector<int> v{0} size() 1 terminate called after throwing an instance of 'std::log
by conbandit 8y ago
Output is:
vector<int> v{3} size() 1
vector<string> v{3} size() 3
vector<int> v{0} size() 1
terminate called after throwing an instance of
'std::logic_error'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
Can anyone explain why there's a logic error?
- clord 8y agoI'd guess it chooses the implicit string(const char*) constructor and then feeds it a nullptr. I think the plan is to get rid of this in the future with the new nullptr_t/nullptr mechanism, but for now we're stuck with it.
- steveklabnik 8y agothat's what /r/cpp says it is
- timriederj 8y agoConstructing with {} uses an initializer list and the () is constructing by setting the size. See more details here: https://stackoverflow.com/questions/33185543/delegating-constructors-in-c-or/33185595#33185595 https://stackoverflow.com/questions/33185543/delegating-cons...