Adding empty element to declared container without declaring type of element
You can take advantage of copy-list-initialization (since C++11) and just write
table.push_back({});
Before C++11 sometimes I use x.resize(x.size()+1)
, in C++11 or later you can use x.push_back({})
.
From CLion's IntelliSense, I later found that one useful method is emplace_back()
. This constructs a new object of correct type and adds it to the end of the vector.
table.emplace_back();