This question already has an answer here:
- Copy std::vector into std::array 2 answers
I am trying to build a std::array
from the data of a std::vector
. I have currently done this :
#include <vector>
#include <array>
int main(void)
{
std::vector<int> vec1;
std::array<int, 5> arr{static_cast<int [5]>(vec.data())};
(void)arr;
return 0;
}
but gcc does not accept this cast :
error: invalid static_cast from type ‘int*’ to type ‘int [5]’
I thought an array could be used as a pointer so why cannot we do this cast ?
Aucun commentaire:
Enregistrer un commentaire