#include <iostream>
#include <vector>
using namespace std;
struct a_struct { int an_int; };
int main ()
{
vector <vector <a_struct> > the_vec;
vector <a_struct> * p_vs;
p_vs = & the_vec[0];
*(p_vs)[0].an_int=0; //error: 'class __gnu_debug_def::vector<a_struct,
//std::allocator<a_struct> >' has no member named 'an_int'
}
I can’t figure out why I’m getting the above compile error.
In C++,
[]and.have higher precedence than*.Your last line
when fully parenthesized, is
Since
p_vswas declared asit is as if
p_vsis an array ofvector <a_struct>elements, sop_vs[0]is avector<a_struct>.And
vector<a_struct>objects indeed do not have a memberan_int.Add some parens and you will get what you want.