我正在尝试使用一些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
答案 0 :(得分:0)
警告1:“ WinMain”:必须为“ _stdcall”
改为使用int main(int argc, char* argv[])
。更多详细信息here。
警告2:“ APIENTRY”:宏重新定义
删除#include <Windows.h>
,您似乎不需要它。
(如果确实需要,请尝试将其放置在其他包含项之上。或者,尝试在#undef APIENTRY
之前添加#include <Windows.h>
。)