SDL和xcode5 - SDL在不同的类
SDL and xcode5 - SDL in different classes
我遇到了以下问题:
我得到了我的主c++文件,其中包括
#include <SDL2/SDL.h>
在写了一些SDL c++代码之后,我想把我的程序分成不同的类。
问题是我试着说:
#include <SDL2/SDL.h>
在新的"引擎"类中,但它似乎不包括SDL。
我使用xcode 5。如果我在main.cpp
中编写代码,SDL框架就可以正常工作。引擎类:
#include "Engine.h"
#include <SDL2/SDL.h>
using namespace std;
class Engine
{
SDL_Window *window = NULL;
SDL_Surface *screenSurface = NULL;
public:
Engine();
bool init();
bool loadMedia();
void close();
}
我还在考虑我需要什么样的课程。这是Engine.h
#ifndef __Engine4__Engine__
#define __Engine4__Engine__
#include <iostream>
#include <SDL2/SDL.h>
class Engine
{
}
#endif /* defined(__Engine4__Engine__) */
当我写SDL_
问题是您没有创建Engine.h
,并且在它不存在时试图引用它。问题不在于SDL,而在于您不确定如何在c++中创建class
。
需要同时创建Engine.h
和Engine.cpp
Engine.h
看起来像
#ifndef ENGINE_H
#define ENGINE_H
#include <SDL2/SDL.h>
class Engine
{
public:
Engine();
bool init();
bool loadMedia();
void close();
private:
SDL_Window *window;
SDL_Surface *screenSurface;
};
#endif
然后你需要创建一个Engine.cpp
文件,看起来像
#include "Engine.h"
Engine::Engine() :
window(nullptr),
screenSurface(nullptr)
{
}
// Rest of code from header file
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- SDL 窗口不会弹出
- SDL 操纵杆按钮按下/C++
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- SDL 映像:无法打开映像,仅显示错误消息
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- "Undefined symbols for architecture x86_64" 在 SDL 2 (macOS) 中
- 为什么 SDL 在 Mac 上比 Linux 慢得多?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- SDL GPU 为什么将两个图像分成两个单独的循环更快?
- 在 cmake 中找不到 SDL 库
- SDL/C++: 如何平滑但随机地移动矩形?
- 如何与 SDL 库链接?
- 为什么我的C++代码不呈现 SDL 矩形?
- 为什么要在初始化SDL之前在SDL中声明指针
- C++/SDL 如何覆盖数组?
- SDL和xcode5 - SDL在不同的类