# 2D vector struct, 1D pointer?

• 01-27-2012
motocross1
2D vector struct, 1D pointer?
Here what I'm doing/trying:
Code:

```struct myStruct{ int iA; double dB; }; vector< vector<myStruct> > data2D; data2D.push_back(vector <myStruct>());// 0 myStruct row; row.iA=1; row.dB=2.3; data2D[0].push_back(row);// 0,0 data2D.push_back(vector <myStruct>());// 1 row.iA=4; row.dB=5.6; data2D[1].push_back(row);// 1,0 vector <myStruct> *pData1D = &data2D[0];// must be wrong? // How do I access iA=1? pData1D[0].iA // of course not pData1D[0]->iA // nope pData1D->[0].iA // and nope```
Thanks
• 01-27-2012
manasij7479
Access from a pointer... or just data2D ?
If the later..just use the [] operator...like "data2D[0][0].iA"
else .. " pData1d->at(0).iA "
• 01-27-2012
motocross1
pData1D->at(0).iA

Bingo!
Thank you very much.
• 01-27-2012
Elysia
(*pData1D)[0].iA should also work.
Additionally, it is unclear why you use a pointer when you can use a reference instead:

vector <myStruct>& pData1D = data2D[0];
pData1D[0].iA
• 01-27-2012
oogabooga
Alternatively
Code:

`int i = (*pData1D)[0].iA;`
• 01-27-2012
motocross1
Elysia,
Reference = wow.
I actually use them as function parameters already.
But, I never knew anything about them before.
I think References are going to be my new favorite discovery.
Thanks