Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:44:20+00:00 2026-05-16T23:44:20+00:00

total noob here with about 2 months of C++ experience (no other background) so

  • 0

total noob here with about 2 months of C++ experience (no other background) so go easy on me.

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

My question is:

If the class player has a private member variable:

char playgrid[15][20];

Is there any reason why an accessor function, defined as:

char getgrid(int index1, int index2)
{
    return playgrid[index1][index2];
}

wouldn’t work?

It’s doing my head in. The error I am getting is:

c2065: ‘playgrid’ undeclared identifier

which points to the line return playgrid[val1][val2] within the accessor definition.

While trying to figure this out, I’ve successfully used my getters to pull values from other private member variables, so everything else is working properly within the object after it is created. I’m definitely not misspelling anything or misusing capitalization. In my constructor, playgrid is initialized as follows:

int i, j;

for (i=0; i<15; i++)
{
    for (j=0; j<20; j++)
    {
        playgrid[i][j]='o';
    }
}

What gives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:44:21+00:00Added an answer on May 16, 2026 at 11:44 pm

    Is there any reason why an accessor
    function, defined as:

    char getgrid(int index1, int index2)
    {
    return playgrid[index1][index2];
    }
    

    wouldn’t work?

    Yes. A function declared like this would not be a member function of a class. You probably meant

    char player::getgrid(int index1, int index2)
    {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px
well...just about all I needed to say...lookie here, I'm a total noob in web
Total noob here with javascript. I'm trying to alter a function. This is the
Total noob here. This is my first c# attempt, its a console application that
Hey! Total CakePHP noob here. Updated at bottom / This is sort of a
First timer here, and total noob when it comes to PHP and JavaScript. I
Total noob question here, but not finding the answer via search. What is the
I'm a total noob to iPhone programming, and I've run into an exception being
Total Python noob here, probably missing something obvious. I've searched everywhere and haven't found
I'm a total noob at Android programming, and wanted to learn how to debug

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.