C++ 我可以在头文件中不包含SDL的情况下编译吗?
在安装带有C++ 我可以在头文件中不包含SDL的情况下编译吗?,c++,visual-studio,sdl-2,vcpkg,C++,Visual Studio,Sdl 2,Vcpkg,在安装带有vcpkg的SDL后,我一直试图让SDL2在Visual Studio中工作。我用了C++和C++的SDL2和 MaxFixs,对我来说很好用。我复制了一些以前用制作文件的C++代码,但是当使用VisualStudio时,它就不能编译了。我一直在头文件上得到一个错误,这是因为它无法识别SDL标识符 使用我的makefile,我不需要在头文件中包括SDL2/SDL.h,只需要在我的cpp文件中。Visual Studio不允许我做同样的事情。这只是我错过的一个场景吗?我真的需要在头文件中
vcpkg
的SDL后,我一直试图让SDL2在Visual Studio中工作。我用了C++和C++的SDL2和<代码> MaxFixs<代码>,对我来说很好用。我复制了一些以前用<代码>制作文件的C++代码,但是当使用VisualStudio时,它就不能编译了。我一直在头文件上得到一个错误,这是因为它无法识别SDL标识符
使用我的makefile
,我不需要在头文件中包括SDL2/SDL.h
,只需要在我的cpp
文件中。Visual Studio不允许我做同样的事情。这只是我错过的一个场景吗?我真的需要在头文件中也包含SDL2/SDL.h
我有一部分代码粘贴在下面。正在为SDL\u窗口
、SDL\u渲染器
和SDL\u颜色
引发错误
//Handler.hpp
#ifndef HANDLER_H_
#define HANDLER_H_
//#include <SDL2/SDL.h> // <- Without this it throws errors
class Handler
{
public:
//variables
SDL_Window * window; //A pointer to the window being handled
SDL_Renderer * renderer; //A pointer to the renderer for the window
unsigned int window_x; //The width of the window
unsigned int window_y; //The height of the window
SDL_Color render_color; //The current drawing color of the renderer
Handler();
Handler(std::string title, unsigned int x, unsigned int y, bool resizable = false, SDL_Color color);
~Handler();
}
#endif //HANDLER_H_
您可能可以对
SDL_窗口
和SDL_渲染器
使用前向声明,但不确定SDL_颜色
看起来Visual Studio正在单独编译头文件,也许您可以以某种方式禁用它,并且只编译.cpp文件。但是,好的做法是在使用头文件时不需要任何特定的顺序(这意味着在头文件中包含SDL)。您是否在Makefile(可能用于预编译的头文件)中使用-include
标志。这真的是编译器错误吗,或者仅仅是Intellisense one?@Jarod42我只选择了构建错误,它给了我一系列错误,告诉我SDL类型之后缺少类型说明符。[OT]:你的类不遵循3/5/0规则。-><代码>处理程序(常量处理程序&)=删除代码>。你有什么办法可以让我这么做吗?我不能肯定你的意思。如果您只想了解结构的结构,我认为渲染器和窗口结构是不完整的类型
//Handler.hpp
#ifndef HANDLER_H_
#define HANDLER_H_
//#include <SDL2/SDL.h> // <- Without this it throws errors
class Handler
{
public:
//variables
SDL_Window * window; //A pointer to the window being handled
SDL_Renderer * renderer; //A pointer to the renderer for the window
unsigned int window_x; //The width of the window
unsigned int window_y; //The height of the window
SDL_Color render_color; //The current drawing color of the renderer
Handler();
Handler(std::string title, unsigned int x, unsigned int y, bool resizable = false, SDL_Color color);
~Handler();
}
#endif //HANDLER_H_