Beginner C++ Using accessors / getters to pull data from a private member variable (2D array) -


There is no Nobel here with about 2 months of C ++ experience (any other background), so be easy for me

I am writing a warship game for programming assignments. The game grid is 15X20 and I am trying to keep the grid as a private member variable of class player .

My question is:

If there is a private member variable in class player

  playwriting [15] [20];  

Is there any reason that an accelerator function, as defined by:

  four gridrid (int index 1, int index 2) {return Playgrid [index 1] [index 2]; }  

Will not work?

This is inserting my head inside. The error I am getting is:

c2065: 'Playgrid' undeclared identifier

for the line line backgrid [val1] [Val2] inside the definition of an accelerator.

While trying to figure out, I have made my personal assumptions other personal members variable, then everything is working properly within the object after I have made it definitely something wrong spelling or I am not misusing capitalization. In my constructor, Playgrid has been launched as the following:

  int i, j; {For (j = 0; j & lt; 20; j ++) {playgrid [i] [j] = 'o'; (i = 0; i & lt; 15; i ++); }}  

What gives?

What is an accelerator function for any reason, as defined: < / P>

  Four gridgreads (int index 1, int index 2) {return playgrid [index 1] [index 2]; }  

Will not work?

Yes a function that has been declared has no member member of the class. You probably mean

  four players :: getgrid (int index1, int index2) {// ...}  

Comments