因此,在完成一本介紹性書籍後,我正在試着用一些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),所以我相信我做了某處出現錯誤。下面是主板創造的相關代碼:)
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(是返回指針空間物體的向量一個很長很長的功能。我懷疑這裏存在問題,因爲當我嘗試訪問main()中的Space對象的圈子成員時,我收到唯一的錯誤消息。在我看來,好像我已在相關範圍內宣佈theBoard
,即作爲理事會類別的數據成員。
我的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;
}
哦,可愛的系統匈牙利符號......(我討厭它!):)我明白'p'的前綴,但從那裏請:不。 – 2011-06-13 18:17:01
@David:是的,這是我的匈牙利用法的限制。我認爲'p'很重要,因爲指針對所需的基本語法有如此巨大的影響。我同意所有'lpsz'微軟的東西都是瘋了! – 2011-06-13 19:21:15