Member not declared in scope?

So, I tried my hand in C ++ after finishing the introductory book, and I'm stuck. I created a vector of objects, each of which has an SFML circle object as a member, and I want main () to go and draw these circles. The vector is called theBoard, but when I try to access it, I get the following error messages:

error: request for member 'theBoard' in 'GameBoard', which is of non-class type 'Board*'
error: 'theBoard' was not declared in this scope

I am new to this (came from two years old Python), so I'm sure I was mistaken somewhere. Here is the appropriate code to create the board:

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. , , , Space main(). , 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;
}
+3
4

, :

error: request for member 'theBoard' in 'GameBoard', which is of non-class type 'Board*'
error: 'theBoard' was not declared in this scope

, Board, . :

Board *p = ...
p.theBoard;     // Error, should be p->theBoard, as p is a pointer

, GameBoard.*theBoard[i].m_Circle , , , , ( , ) - GameBoard->theBoard[i]->m_Circle.

+3

main() GameBoard Board *, Board. -> .. :.

GameBoard->theBoard.size()

[ ( ) p ptr, .]

+6

GameBoard - Board, "- > " ".". - .

+4

GameBoard is a pointer, so the syntax should be as follows:

 for(int i = 0; i < GameBoard->theBoard.size(); ++i)
 {
        App.Draw((GameBoard->theBoard[i])->m_Circle);
 }

Since elements theBoardare also pointers, so I used the pointer designation when accessing m_Circle.

+3
source

All Articles