With the former you can call vector.push_back(type());
With the latter, you can call vector.resize(number_of_pointers_to_type);
If you are constructing objects (non-primitives), their constructor is always called. IE, vector.push_back(type()) constructs a default instance of type, then calls it's copy constructor.
Code:
#include <vector>
#include <iostream>
class test {
public:
test() {
std::cout << "test::test()" << std::endl;
}
test(const test& o) {
std::cout << "test::test(const test&)" << std::endl;
}
};
int main() {
std::vector<test> vecOfValues;
vecOfValues.push_back(test());
std::vector<test*> vecOfPointers;
vecOfPointers.resize(3); // 3 null pointers
for (int i = 0; i < 3; ++i) {
std::cout << vecOfPointers[i] << '\n';
}
return 0;
}
Use a vector of values unless you need polymorphism.