2011-08-03 208 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完全是另一回事。

相关问题