0

我正在尝试使用一些 SDL2 编码打开一个窗口。但是,每次我尝试编译和运行代码时,Visual Studio 总是给我同样的错误。

Error: 'identifier' : function cannot be overloaded

这是我的代码:

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_image.h>
#include <Windows.h>
using namespace std;

const int WIDTH = 800, HEIGHT = 600;

int WinMain(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = SDL_CreateWindow("Hello SDL World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);

    // Check that the window was successfully created
    if (NULL == window)
    {
        // In the case that the window could not be made...
        std::cout << "Could not create window: " << SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Event windowEvent;

    while (true)
    {
        if (SDL_PollEvent(&windowEvent))
        {
            if (SDL_QUIT == windowEvent.type)
            {
                break;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return EXIT_SUCCESS;


}

以下是他们给我的一些警告,以防万一:

Warning #1: 'WinMain': Must be '_stdcall'

Warning #2: 'APIENTRY': macro redefinition
4

1 回答 1

0

警告 #1:“WinMain”:必须是“_stdcall”

改为使用int main(int argc, char* argv[])。更多细节在这里

警告 #2:“APIENTRY”:宏重新定义

删除#include <Windows.h>,您似乎不需要它。

(如果您确实需要它,请尝试将其放在其他包含之上。或者,尝试在 .#undef APIENTRY之前添加#include <Windows.h>。)

于 2018-11-30T20:24:15.863 回答