As a test, I wrote a code sample that includes a pointer to a vector in a struct. It attempts to create an instance of the struct, assign a new vector to it, assign a value to one of the vector's members, and then print that value as read from the vector.
Code: Select all
#include <iostream>
#include <vector>
using namespace std;
typedef struct {
__int64 size = 0;
vector<__int64>* array;
} int_array;
int main () {
int_array num_array;
num_array.array = new vector<__int64>;
num_array.array->reserve(5);
(*num_array.array)[0] = 5;
cout << (*num_array.array)[0];
return 0;
}
However, when I run the code, I get an error "vector subscript out of range". Am I doing something wrong?