#include <iostream>
#include <vector>
using namespace std;
struct s_Astruct {
vector <int> z;
};
int main ()
{
vector <s_Astruct> v_a;
for(int q=0;q<10;q++)
{
v_a.push_back(s_Astruct());
for(int w =0;w<5;w++)
v_a[q].z.push_back(8);
}
vector <s_Astruct> * p_v_a = & v_a;
cout << p_v_a[0]->z[4]; //error: base operand of '->' has non-pointer type
//'__gnu_debug_def::vector<s_Astruct, std::allocator<s_Astruct> >'
}
There seems to be some issue with this sort of operation that I don’t understand. In the code that I’m working on I actually have things like p_class->vector[]->vector[]->int; and I’m getting a similar error.
You want to do this:
What you are doing is dereferencing the pointer by using [] and grabbing the 0’th offset, and then trying to dereference the non-pointer.
Another way to do it (which is just ugly):