There are many solutions, here’s a few I’ve come up with:
int main(int nArgs, char ** vArgs) { vector<int> *v = new vector<int>(10); v->at(2); //Retrieve using pointer to member v->operator[](2); //Retrieve using pointer to operator member v->size(); //Retrieve size vector<int> &vr = *v; //Create a reference vr[2]; //Normal access through reference delete &vr; //Delete the reference. You could do the same with //a pointer (but not both!) }
Related Posts:
- C++ – No matching member function for call to ‘push_back’
- How to initialize a vector of pointers
- 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++?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- Vector of Vectors to create matrix
- How to find out if an item is present in a std::vector?
- 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?
- Initializing a two dimensional 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?
- 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?
- 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?
- 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?
- What is the use of intptr_t?
- 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
- error C2106: ‘=’ : left operand must be l-value
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- 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
- “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
- C++ Swapping Pointers
- Array of Linked Lists C++
- “Cannot allocate an object of abstract type” error