ですから、入門書を書き終えた後、C ++を試してみましたが、行き詰まってしまいました。それぞれがメンバーとしてSFML円オブジェクトを持つオブジェクトのベクトルを作成しました。main()にこれらの円を描画させたいと思います。ベクトルはと呼ばtheBoard
れますが、それにアクセスしようとすると、次のエラーメッセージが表示されます。
error: request for member 'theBoard' in 'GameBoard', which is of non-class type 'Board*'
error: 'theBoard' was not declared in this scope
私はこれに慣れていないので(Pythonの2年間から来ました)、どこかで間違いを犯したと確信しています。ボード作成に関連するコードは次のとおりです。
class Board
{
public:
//These are the member functions.
Board();
~Board();
vector<Space*> CreateBoard();
//This will be the game board.
vector<Space*> theBoard;
//These clusters represent the waiting areas for pieces not yet in the game.
vector<Space*> Cluster1;
vector<Space*> Cluster2;
vector<Space*> Cluster3;
private:
//These integers represent the number of spaces on each row, starting at the top (which is row [0])
vector<int> RowNums;
};
Board::Board()
{
//Fill in RowNums with the right values.
RowNums.push_back(1);
RowNums.push_back(17);
RowNums.push_back(2);
RowNums.push_back(17);
RowNums.push_back(1);
RowNums.push_back(1);
RowNums.push_back(5);
RowNums.push_back(2);
RowNums.push_back(7);
RowNums.push_back(2);
RowNums.push_back(11);
RowNums.push_back(3);
RowNums.push_back(17);
RowNums.push_back(4);
RowNums.push_back(17);
//Then, create the board.
theBoard = CreateBoard();
}
CreateBoard()は、Spaceオブジェクトへのポインターのベクトルを返す非常に長い関数です。main()でSpaceオブジェクトのサークルメンバーにアクセスしようとすると、エラーメッセージが表示されるだけなので、ここに問題があるとは思えません。theBoard
私は、関連するスコープで、つまり、Boardクラスのデータメンバーとして宣言したように見えます。
重要な場合の私のmain()関数:
int main()
{
//This sets up the display window.
sf::RenderWindow App(sf::VideoMode(1200, 900, 32), "Malefiz");
//This creates the board on the heap, and a pointer to it.
Board* GameBoard = new Board();
cout << "Board made.";
//This is the game loop.
while(App.IsOpened())
{
//This is used to poll events.
sf::Event Event;
while(App.GetEvent(Event))
{
//This closes the window.
if(Event.Type == sf::Event::Closed)
{
App.Close();
}
}
//This gets the time since the last frame.
//float ElapsedTime = App.GetFrameTime();
//This fills the window with black.
App.Clear(sf::Color(200, 200, 125));
//This draws the places into the window.
for(int i = 0; i < GameBoard.theBoard.size(); ++i)
{
App.Draw(GameBoard.*theBoard[i].m_Circle);
}
//This displays the window.
App.Display();
}
return EXIT_SUCCESS;
}