我不明白這個錯誤它寫在教程完全相同的,但我的一個產生一個錯誤錯誤C2059:語法錯誤:「(」
#include "drawEngine.h"
#include <Windows.h>
#include <iostream>
using namespace std;
DrawEngine::DrawEngine(int xSize, int ySize)
{
screenWidth = xSize;
screenHeight = ySize;
//set cursor visibility to false
map = 0;
cursorVisibility(false);
}
DrawEngine::~DrawEngine()
{
//set cursor visibility to true
cursorVisibility(true);
}
int DrawEngine::createSprite(int index, char c)
{
if (index >= 0 && index < 16)
{
spriteImage[index] = c;
return index;
}
return -1;
}
void DrawEngine::deleteSprite(int index)
{
//in this implementation we don't need it
}
void DrawEngine::drawSprite(int index, int posx, int posy)
{
//go to the correct location
gotoxy(posx, posy);
//draw the image with cout
cout << spriteImage[index];
}
void DrawEngine::eraseSprite(int posx, int posy)
{
gotoxy(posx, posy);
cout << ' ';
}
void DrawEngine::setMap(char **data)
{
map = data;
}
void DrawEngine::createBackgroundTile(int index, char c)
{
if (index >= 0 && index < 16)
{
tileImage[index] = c;
}
}
void DrawEngine::drawBackground(void)
{
if (map)
{
for (int y = 0; y < screenHeight; y++)
{
goto(0, y); // This generates the error
for (int x = 0; x < screenWidth; x++)
{
cout << tileImage[map[x][y]];
}
}
}
}
void DrawEngine::gotoxy(int x, int y)
{
HANDLE output_handle;
COORD pos;
pos.X = x;
pos.Y = y;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output_handle, pos);
}
void DrawEngine::cursorVisibility(bool visibility)
{
HANDLE output_handle;
CONSOLE_CURSOR_INFO cciInfo;
cciInfo.dwSize = sizeof(CONSOLE_CURSOR_INFO);
cciInfo.bVisible = visibility;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(output_handle, &cciInfo);
}
它聲稱錯誤發生在哪條線上 –
您必須提及發生了什麼行號(剛剛粘貼的代碼) – Reno
作爲旁註,您可能只想複製最小的相關代碼段這會在下次再現錯誤。讀取特定於問題的四行比讀取錯誤的50行更容易。 – Cameron