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

  • SEARCH
  • Home
  • 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 6772031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:30:06+00:00 2026-05-26T15:30:06+00:00

I am trying to compile this code: class OthelloState { public: // constructor Othello(int

  • 0

I am trying to compile this code:

class OthelloState {
public: // constructor 

    Othello(int r, int c);

/* other stuff */

private: // private data

    const int rows;

    const int columns;

    int board[rows][columns];
}

I keep ending up with:

OthelloState.h:109: error: invalid use of non-static data member 'OthelloState::rows'
OthelloState.h:115: error: from this location
OthelloState.h:115: error: array bound is not an integer constant
OthelloState.h:112: error: invalid use of non-static data member 'OthelloState::columns'
OthelloState.h:115: error: from this location
OthelloState.h:115: error: array bound is not an integer constant

I assume that this means I have to make rows and columns static. But if I make them static, I cannot initialize either with from a constructor, the way I have to for this project…

Is there some other way I can do this?

PS: I know that in real Othello, the board is a square 8 by 8 grid…But after considering how long it would take the computer to generate the next best move on a partial 8 by 8 grid, we are not going to play with “real” Othello board (i.e. no predefined board sizes).

  • 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-26T15:30:07+00:00Added an answer on May 26, 2026 at 3:30 pm

    In C++, variable length arrays are not allowed. board[][] needs to know both of its dimensions at compile time. You can use vector<vector<int> > board;, if you want to initialize row and col at runtime.

    class OthelloState {
    public:
        OthelloState(int r, int c);
    
    private: // private data
        const int rows;  // should be 'unsigned int'
        const int columns;
    
        vector<vector<int> > board;  
    };
    

    Other solution:

    Suppose you know rows and cols at compile time then you can use template. That is as good as initializing row and col in constructor.

    template<unsigned int row, unsigned int col>
    class OthelloState {
    public:
    ...
    private:
      int board[row][col];
    };
    

    Usage:

      OthelloState<8,8> obj;
      OthelloState<10,10> obj;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile a POCO with this code public class MenuItem { public
i am trying to compile this very simple piece of code class myList {
I'm trying to compile the following code: class MyClass { def foo(): this.type =
hI, I'm trying to get this code from Larry Nyhoff's book to compile in
I'm trying to compile this code with GCC 4.5.0: #include <algorithm> #include <vector> template
I m trying to compile this code and linking fails with the following error:
Was trying to compile some code from this SO question and run into this
So I am trying to compile this simple code: // In Test.h #include <iostream>
I'm trying to compile this function from Learn You a Haskell for Great Good
Trying to compile a iPhone/iPad application with SDK3.2 and am getting this error: Undefined

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.