我正在嘗試學習如何使用glad和glfw在c中制作游戲和模擬。嘗試將Window任何函式中的結構用作引數或僅宣告Window實體時,會發生此錯誤。我收到'Window': undeclared identifier錯誤。我明白這可能意味著通過研究 stackoverflow 上的錯誤,我有一個回圈包含(我似乎無法弄清楚在哪里)。(我對 c 很陌生,所以我很感激任何幫助)
核心.h:
#ifndef MINECRAFTCLONE_CORE_H
#define MINECRAFTCLONE_CORE_H
#include <stdio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
extern int error(char* error);
#endif
核心.c:
#include "Core.h"
int error(char* error)
{
printf("%s", error);
return -1;
}
視窗.h:
#ifndef CORE_WINDOW_H
#define CORE_WINDOW_H
#include "Core.h"
struct Window
{
int width;
int height;
char* title;
GLFWwindow* res;
};
extern int coreCreateWindow(struct Window* window, int width, int height, char* title);
extern int coreLoopWindow(struct Window* window);
#endif
視窗.c:
#include "Core.h"
#include "Window.h"
int coreCreateWindow(struct Window* window, int width, int height, char* title)
{
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if (!glfwInit())
return error((char*)"Failed to initialize glfw");
window->width = width;
window->height = height;
window->title = title;
window->res = glfwCreateWindow(window->width, window->height, window->title, 0, 0);
if (!window->res)
return error((char*)"Failed to create glfw window");
glfwMakeContextCurrent(window->res);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
return error((char*)"Failed to initialize glad");
return 0;
}
int coreLoopWindow(struct Window* window)
{
while (!glfwWindowShouldClose(window->res))
{
glfwPollEvents();
}
glfwDestroyWindow(window->res);
glfwTerminate();
return 0;
}
主檔案:
#include "Core.h"
#include "Window.h"
int main()
{
Window* window;
return 0;
}
uj5u.com熱心網友回復:
你還沒有定義一個叫做的型別Window,你可以定義一個變數,比如
Window *window;
您已經定義的struct Window與您定義window的變數main()一樣
struct Window *window;
以同樣的方式,您已經定義了所有函式原型的window引數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380471.html
上一篇:組合不同的arityX宏
