1// Heap allocated array in c++
2//using std::vector
3#include <vector>
4std::vector<myarray> bestArray(100); //A vector is a dynamic array, which (by default) allocates elements from the heap
5
6//or managing memory yourself
7myarray* heapArray = new myarray[100];
8delete [] heapArray; // when you're done
9
10//How to use vector to put elements inside the array.
11// C++11:
12std::vector<myarray> bestArray{ 1, 2, 3 };
13
14// C++03:
15std::vector<myarray> bestArray;
16bestArray.push_back(myarray(1));
17bestArray.push_back(myarray(2));
18bestArray.push_back(myarray(3));
19
1//Heap array
2std::array<myarray, 3> stack_array; // Size must be declared explicitly.VLAs
3
4//Stack array
5std::vector<myarray> heap_array (3); // Size is optional.
6