在 SDL_CreateWindow() 函数中获取"too few arguments in function call"错误


#include <iostream>
#include <SDL2/SDL.h>
using namespace std;
const int sWidth = 800, sHeight = 800;
int main() {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window  = SDL_CreateWindow("My SDL", SDL_WINDOWPOS_UNDEFINED, sWidth, sHeight, SDL_WINDOW_ALLOW_HIGHDPI);
}

文档指出SDL_CreateWindow需要六个参数,但您只提供了五个。编译器也在告诉你同样的事情。

试试这个

SDL_Window *window = SDL_CreateWindow("My SDL", 
SDL_WINDOWPOS_UNDEFINED, 
SDL_WINDOWPOS_UNDEFINED, 
sWidth, sHeight, SDL_WINDOW_ALLOW_HIGHDPI);

如文档页面所述,SDL_CreateWindow()具有以下签名:

SDL_Window * SDL_CreateWindow(const char *title,
int x, int y, int w,
int h, Uint32 flags);

正如您所看到的,您缺少int y窗口位置参数。

既然你已经开始学习了,我建议你去看看教程。懒虫有一些非常有用的东西:https://lazyfoo.net/tutorials/SDL/.

相关内容

最新更新