0
我正在使用基本的Windows控制檯進行遊戲的屏幕上工作。使用動態分配數組的C++函數中有趣的語法錯誤
不幸的是,我得到這個錯誤
1>d:\users\chris\documents\programs\testing\roguelike mkii\roguelike mkii\screen.h(49): error C2143: syntax error : missing ';' before '['
1>d:\users\chris\documents\programs\testing\roguelike mkii\roguelike mkii\screen.h(49): error C2337: 'pPoint' : attribute not found
1>d:\users\chris\documents\programs\testing\roguelike mkii\roguelike mkii\screen.h(49): error C2143: syntax error : missing ']' before '.'
1>d:\users\chris\documents\programs\testing\roguelike mkii\roguelike mkii\screen.h(49): error C2143: syntax error : missing ';' before '.'
,我似乎無法擺脫它。
另外在setChar()函數中,pPoint.nX表示它必須是常量,我無法理解。
struct pointOnScreen
{
char character;
int colour;
};
class Screen
{
private:
const int xLength;
const int yLength;
pointOnScreen** screen;
public:
Screen() : xLength(80), yLength(24)
{
screen = new pointOnScreen*[xLength];
for(int ix = 0; ix < xLength; ix++)
{
screen[ix] = new pointOnScreen[yLength];
for(int iy = 0; iy < yLength; iy++)
{
screen[ix][iy].character = ' ';
screen[ix][iy].colour = 0;
}
}
}
~Screen()
{
for(int i = 0; i < xLength; i++)
{
delete[] screen[i];
}
delete[] screen;
}
void setChar(char toSet, point pPoint)
{
pointOnScreen[pPoint.nX][pPoint.nY] = toSet;
}
};
提前許多感謝所有幫助
使用向量的載體或專門的矩陣。你的班級行爲不正常。那些會使它正常運行,並讓你擺脫你的析構函數來啓動。 – chris 2014-11-08 22:35:41
謝謝,這只是我使用結構,而不是變量 – Cjen1 2014-11-08 22:44:34