错误 C2059:语法错误:'('

error c2059: syntax error: '('

本文关键字:错误 语法 C2059      更新时间:2023-10-16

我不理解这个错误——教程中写的完全一样,但我的错误产生了一个错误。

#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);
}

我想你是想写gotoxy(0, y)而不是goto(0, y)

goto是一个跳转到标签的C++关键字,例如:

home:
goto home;    // Loops forever

不过,不要使用它,创建意大利面条代码太容易了。

goto(0, y)可能应该是gotoxy(0, y)goto是C中的保留关键字,不能用作函数名。

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