ошибка c2059: синтаксическая ошибка: '(' - PullRequest
0 голосов
/ 03 августа 2011

Я не понимаю эту ошибку, она написана точно так же в учебнике, но моя выдает ошибку.

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

Ответы [ 3 ]

7 голосов
/ 03 августа 2011

Я думаю, что вы хотели написать gotoxy(0, y) вместо goto(0, y).

goto - это ключевое слово C ++, которое переходит на метку, например:

home:
goto home;    // Loops forever

Не используйте его, однако, слишком легко создавать код для спагетти.

0 голосов
/ 03 августа 2011

Я думаю, что вы имели в виду gotoxy. goto это совсем другое.

0 голосов
/ 03 августа 2011

goto(0, y), вероятно, должно быть gotoxy(0, y).goto является зарезервированным ключевым словом в C и не может использоваться в качестве имени функции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...