difference between <int*> and <int>* with vector

What is the difference between the following lines of code?

1
2
3
4
5
6
#include <vector>

vector <int>* n;
vector<int*> n;

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int integer ; // integer is an object of type 'int'

int* pointer_to_int ; // pointer_to_int is an object of type 'pointer to int'
using pint = int* ; // type 'pint' is another name for type 'pointer to int'
typedef int* pint ; // same as above; type 'pint' is another name for 'pointer to int'

std::vector<int>  vec1 ;  // vec1 is a vector containing objects of type 'int'

std::vector<int*>  vec2 ;  // vec2 is a vector containing objects of type 'pointer to int'
std::vector<pint>  vec3 ;  // vec3 is a vector containing objects of type 'pointer to int'

using vec_type = std::vector<int> ;  // type 'vec_type' is another name for type "vector containing objects of type 'int'"
vec_type vec4 ; // vec4 is a vector containing objects of type 'int'

std::vector<int>*  vec5 ;  // vec5 is a pointer to a vector containing objects of type 'int'
vec_type*  vec6 ;  // vec6 is a pointer to a vector containing objects of type 'int'

std::vector<int*>*  vec7;  // vec7 is a pointer to a vector containing objects of type 'pointer to int'

int i = 1, j = 2, k = 3 ;

std::vector<int> vector_of_integers = { i, j, k } ;

std::vector<int*> vector_of_pointers_to_integers = { &i, &j, &k } ;

std::vector<int>* pointer_to_vector_of_integers = std::addressof(vector_of_integers) ; // &vector_of_integers

std::vector<int*>* pointer_to_vector_of_pointers_to_integers = std::addressof(vector_of_pointers_to_integers) ;
JLBorges is the man
Topic archived. No new replies allowed.