It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,
visit the help center
.
If this question can be reworded to fit the rules in the
help center
, please
edit the question
.
A vector of pointers to newly allocated objects (not really initialization though):
std::vector<int*> stuff;
stuff.reserve(10);
for( int i = 0; i < 10; ++i )
stuff.push_back(new int(i));
Initializing a vector of pointers to newly allocated objects (needs C++11):
std::vector<int*> widgets{ new int(0), new int(1), new int(17) };
A smarter version of #3:
std::vector<std::unique_ptr<int>> stuff;
stuff.reserve(10);
for( int i = 0; i < 10; ++i )
stuff.emplace_back(new int(i));
–
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0
with attribution required.
rev 1.0.0.0