A zero-size vector of pointers:
std::vector<int*> empty;
A vector of NULL pointers:
std::vector<int*> nulled(10);
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));
Related Posts:
- C++ – No matching member function for call to ‘push_back’
- How to access the contents of a vector from a pointer to the vector in C++?
- clearing a vector of pointers [duplicate]
- How to implement 2D vector array?
- What are the differences between a pointer variable and a reference variable in C++?
- How do I print out the contents of a vector?
- Return array in a function
- What does “dereferencing” a pointer mean?
- Regular cast vs. static_cast vs. dynamic_cast
- What is a smart pointer and when should I use one?
- What does “dereferencing” a pointer mean?
- What is a char*?
- check if a std::vector contains a certain object?
- What exactly is nullptr?
- How to navigate through a vector using iterators? (C++)
- C++ for each, pulling from vector elements
- How do I erase an element from std::vector<> by index?
- How to fix a “invalid operands to binary expression” error?
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]
- How do I reverse a C++ vector?
- What is a dangling pointer?
- Debug assertion failed. C++ vector subscript out of range
- What does `*&` in a function declaration mean?
- No matching member function for call to ‘push_back’ error
- (->) arrow operator and (.) dot operator , class pointer
- Pass a vector by reference C++
- What is uintptr_t data type
- What is the difference between const int*, const int * const, and int const *?
- Why there is no pop_front method in C++ std::vector?
- What is uintptr_t data type
- What does int & mean
- What is the difference between const int*, const int * const, and int const *?
- Debug assertion failed. C++ vector subscript out of range
- Vector is not a Template?
- Displaying a vector of strings in C++
- ‘vector’ in namespace ‘std’ does not have a template type
- Pointer to incomplete class type is not allowed
- C++ error: Undefined symbols for architecture x86_64
- Vector of structs initialization
- Passing a 2D array to a C++ function
- Converting a vector
to string - vector
::size_type in C++ - Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- Why use a new call with a C++ ‘vector’?
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- Why doesn’t std::vector::push_front() exist?
- C++ delete vector, objects, free memory
- How to iterate over a vector?
- Insert object at index of vector c++
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- How to convert vector to array
- No operator << matches these operands
- Initialize empty vector in structure – c++
- What does int & mean
- C++: Expression must have a constant value when declaring array inside function
- splitting a string into an array in C++ without using vector
- Sorting Linked List C++ with pointers
- Delete 2D array C++
- Is the sizeof(some pointer) always equal to four?
- What’s the most efficient way to erase duplicates and sort a vector?
- Best way to extract a subvector from a vector?
- Appending a vector to a vector
- C++ Expression must have pointer-to-object type
- C++ strings and pointers
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- C++ Erase vector element by value rather than by position?
- C++ – Assigning null to a std::string
- Correct way to work with vector of arrays
- C++ error: double free or corruption (fasttop)
- error C2106: ‘=’ : left operand must be l-value
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- Reference to non-static member function must be called
- Why use pointers?
- I get this error: “glibc detected”
- What’s the difference between * and & in C?
- C++ pass an array by reference
- How to create a vector of class objects in C++?
- “vector” was not declared in this scope
- Function stoi not declared
- C++ Array of pointers: delete or delete []?
- Why should I use a pointer rather than the object itself?
- Function stoi not declared
- Vector declaration “expected parameter declarator”
- Why is this vector iterator not incrementable?
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- Initializing pointers in C++
- Why can’t I make a vector of references?
- Difference between function arguments declared with & and * in C++
- Is C++ Array passed by reference or by pointer?
- Difference between the int * i and int** i
- set head to NULL (‘NULL’ : undeclared identifier)
- Displaying contents of a vector container in C++
- What is the size of sizeof(vector)? C++
- What is a `char*`?
- c++ vector bubble sort
- Array of Linked Lists C++
- “Cannot allocate an object of abstract type” error
- Differences between unique_ptr and shared_ptr