Expand|Select|Wrap|Line Numbers
- struct board
- {
- int r;
- int c;
- };
- void rd(vector <struct board> cp)
- {
- cout<<"\nr="<<cp[0].r;
- cp[0].r=8;
- }
- //---------------------
- /*This Read function should catch the vector reference and
- any modification done to this cp should affect the cpy in main()*/
- //---------------------
- void read(vector <struct board> cp)
- {
- for(int i=0;i<4;i++)
- for(int j=0;j<4;j++)
- {
- struct board x;
- x.r=i;
- x.c=j;
- cp->push_back(x);
- }
- rd(*cp);
- cout<<"\nr="<<cp[0].r;
- //---------------------------------------
- /*How do I access the r and c in the cp? I have tried a lot of thinsg but
- was unsuccessful in accessing the r and c in cp[0]? */
- //---------------------------------------
- }
- void main()
- {
- vector <struct board> cpy;
- read(&cpy);
- for(int i=0;i<4;i++)
- //for(int j=0;j<4;j++)
- cout<<"\nCpy took "<<cpy[i].r<<" , "<<cpy[i].c<<endl;
- //-------------------
- Any effects in the functions to cpy by call by
- reference should affect this cpy too...
- }
1 is call by reference for vector array variables...
2 is accessing the r and c in the cpy struct variable through the pointer?
Please help....
I was actually trying to use the single dimentional array for declaring this i.e.
struct board x[50];
but this said that I was supposed to initialize all the variables as this was not easy I thought of shifting to vectors and now I have this problem...
Thank You in advance...
Regards,
Digital Don...