Acessing a struct member, using a pointer to a vector of structs. Error:base operand of '->' has non-pointer type
Posted
by
Matt Munson
on Stack Overflow
See other posts from Stack Overflow
or by Matt Munson
Published on 2011-01-14T14:31:12Z
Indexed on
2011/01/14
14:53 UTC
Read the original article
Hit count: 167
#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.
© Stack Overflow or respective owner