不完整的类型不允许错误
Incomplete type not allowed error
我创建了一个使用OpenGL显示标签(GameLabel)的类,我遇到了我无法解决的2个非常奇怪的错误。
错误c2079:'displayplayer'使用未定义的类'gamelabel'Intellisense:不允许使用不完整的类型
这是我的代码;
game.cpp中的函数调用标签类
void Game::draw(SDL_Window *window)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear window
// draw player
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f (xpos, ypos, 0.0); // first corner
glVertex3f (xpos+xsize, ypos, 0.0); // second corner
glVertex3f (xpos+xsize, ypos+ysize, 0.0); // third corner
glVertex3f (xpos, ypos+ysize, 0.0); // fourth corner
glEnd();
GameLabel displayPlayer = new GameLabel(xpos+(xsize/2.0f), ypos+ysize, "Player");
//The ablove line is the one flagging the errors.
现在是gamelabel.h。
#include <SDL_ttf.h>
#include <GL/glew.h>
#include <string>
#include "Game.h"
class GameLabel
{
public:
GameLabel(float fx, float fy, char stri);
~GameLabel(void);
void textToTexture(const char * str, SDL_Surface* stringImage);
void draw(SDL_Surface* stringImage);
friend class Game;
protected:
SDL_Surface stringImage;
private:
GLuint texID;
GLuint height;
GLuint width;
GLfloat x;
GLfloat y;
char str;
};
最后是gamelabel.cpp构造函
GameLabel::GameLabel(float fx, float fy, char stri)
{
x = fx;
y = fy;
str = stri;
}
可能是由于循环依赖吗?gamelabel包括game.h ..
在您的所有.h文件上都写在最顶部:
#ifndef YOUR_FILE_NAME_H_
#define YOUR_FILE_NAME_H_
这是最底层的:
#endif
替换您使用的.h文件名替换your_file_name_h_,最好使用大写。
这将防止头部文件多次包含。
相关文章:
- 错误:在第 6 行'{'标记之前,此处不允许使用函数定义
- C++错误:此上下文中不允许使用分解声明
- 内建数组出现不允许的类型不完整错误
- 数组错误(不允许类型不完整)
- 错误消息:不允许抽象类类型 "X" 的对象:纯虚拟"Y"没有覆盖器
- 错误:不允许使用抽象类类型的对象
- 网站组装 |错误:'C/ObjC'不允许使用无效'-std=c++11'参数
- 不允许调用 gil 要求函数,否则 gil 编译错误与 C++
- 我在代码中有一个错误,错误是:(智能感知:不允许抽象类类型"HourlyWorker"的对象:)
- 不允许使用错误类型
- 奇怪的不完整类型不允许错误
- Arduino / esp8266:错误:'Pchr 不允许部分属性
- 错误 - 此处不允许在 { 令牌之前使用函数定义
- 模板函数调用中C++错误:不允许使用类型名称
- 虚幻引擎 4.18.0,VS2017,不允许指向不完整类类型的错误指针
- 不允许向量<auto>吗?(错误:"自动"的使用无效)
- C++ 错误 - <unnamed-tag>不允许匿名联合的成员使用 cass 内初始值设定项
- 错误 C2491:不允许定义 dllimport 函数
- 不完整的类型不允许错误
- 类型不完整不允许错误,如何修复