错误 c2059:语法错误:'('

发布于 2024-11-27 21:01:41 字数 2074 浏览 2 评论 0原文

我不明白这个错误,它在教程中写得完全相同,但我的错误生成了一个错误。

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

I don't understand this error it's written the exact same in the tutorial but my one generates an error.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

全部不再 2024-12-04 21:01:41

我认为您的意思是编写 gotoxy(0, y) 而不是 goto(0, y)

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

home:
goto home;    // Loops forever

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

I think you meant to write gotoxy(0, y) instead of goto(0, y).

goto is a C++ keyword which jumps to a label, for example:

home:
goto home;    // Loops forever

Don't use it, though, it's too easy to create spaghetti code.

姜生凉生 2024-12-04 21:01:41

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

The goto(0, y) should probably be gotoxy(0, y). goto is a reserved keyword in C and cannot be used as a function name.

梦途 2024-12-04 21:01:41

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

I think you meant gotoxy. goto is something else entirely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文