配列の範囲を指定する定数static int変数を作成します。私は問題に遭遇し、変数がクラスのメンバーではないというエラーが出ていますが、ClassName :: staticVarNameを使用してmainの変数を出力できます。配列を初期化する際にconst staticメンバを使用しようとしていません
クラスに属する静的変数を正しく設定して、配列の初期化に使用できるようにする方法がわかりません。変数はmainに出力されますが、何らかの理由でクラスの配列フィールドの範囲を定義するために変数を使用しようとするとコンパイルされません。
error: class "RisingSunPuzzle" has no member "rows"
error: class "RisingSunPuzzle" has no member "cols"
クラスのヘッダファイル:
#pragma once
#include<map>
#include<string>
#include<memory>
class RisingSunPuzzle
{
private:
bool board[RisingSunPuzzle::rows][RisingSunPuzzle::cols];
public:
RisingSunPuzzle();
~RisingSunPuzzle();
static const int cols;
static const int rows;
void solvePuzzle();
void clearboard();
};
クラスのcppのファイル:
#include "RisingSunPuzzle.h"
const int RisingSunPuzzle::cols = 5;
const int RisingSunPuzzle::rows = 4;
RisingSunPuzzle::RisingSunPuzzle()
{
}
RisingSunPuzzle::~RisingSunPuzzle()
{
}
void RisingSunPuzzle::solvePuzzle()
{
}
void RisingSunPuzzle::clearboard()
{
}
のように(初期化子なし)それらを定義することができます。 – doug