some questions about reference and array

Q1:
EG: int array[size];
Can I use:
int &reference = array;
and then
sth = reference[3]?

Q2:
if I wanna to creat a flexible array in a class,which i can change the array size through a public function, what should i do? Make a pointer? I think it is
not that simple....

thanks for help.
Q1:
you can do this:
1
2
3
int array[size];
int (&reference)[size] = array;
sth = reference[3];


Q2:
You already have STL containers eg: vectors
1
2
vector <int> array ( 4 );
array.resize(5);

http://www.cplusplus.com/reference/stl/vector/
Last edited on
Topic archived. No new replies allowed.