2011-08-03 234 views
0

我不明白這個錯誤它寫在教程完全相同的,但我的一個產生一個錯誤錯誤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); 
} 
+0

它聲稱錯誤發生在哪條線上 –

+0

您必須提及發生了什麼行號(剛剛粘貼的代碼) – Reno

+0

作爲旁註,您可能只想複製最小的相關代碼段這會在下次再現錯誤。讀取特定於問題的四行比讀取錯誤的50行更容易。 – Cameron

回答

6

我想你的意思是寫gotoxy(0, y)代替。 。goto(0, y)

goto是跳轉到一個標籤,例如C++關鍵字:

home: 
goto home; // Loops forever 

不要使用它,但是,它太容易創建小號意大利麪代碼。

+0

謝謝,下次我看看教程更近 – Blackelfwolf

+1

這是一個不正常的函數名稱錯誤信息,因爲goto是一個關鍵字;) –

+0

它的代碼是_label_。 _label_不能包含'('。 –

0

goto(0, y)應該可能是gotoxy(0, y)goto是C中的保留關鍵字,不能用作函數名稱。

0

我想你的意思是gotoxygoto完全是另一回事。