我偶然发现了继承问题。所以我在3个单独的头文件中有3个类,如下所示:
GenericObject - >宾语 GenericObject - > LightObject
首先是继承的对象:
#ifndef GENERICMODEL_HPP
#define GENERICMODEL_HPP
#define NO_SDL_GLEXT
#define GLM_FORCE_RADIANS
#include <GL/glew.h>//before opengl
#include <SDL2/SDL.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <glm/glm.hpp>
#include <vector>
#include <glm/gtc/matrix_transform.hpp>
#include "GenericShader.hpp"
#include "BaseObject.hpp"
#include "Scene.hpp"
#define FRAGMENT_SHADER 0
#define VERTEX_SHADER 1
class GenericShader;
class Scene;
class GenericModel: public BaseObject{
public:
GenericModel();
~GenericModel();
virtual void Render();
bool LoadShaderProgram(char*,char*);
void BindShaders(GenericShader *);
void UpdatePosition(glm::vec3);
void UpdateRotation(float,glm::vec3);
void UpdateScale(glm::vec3);
void UpdateMatrix();
bool shadersLoaded;
int scenePosNum = 0;
GLuint programID;//for now
GLuint vertexBuffer;
glm::mat4 MVP;
glm::mat4 modelMatrix;
//Scene *scene;
protected:
GenericShader *shaderObj= NULL;
GLuint vaoID;
Uint32 verticesCount;
float angle;
glm::vec3 locationVector;
glm::vec3 rotationVector;
glm::vec3 scaleVector;
Scene *scene;
};
#endif
第二
#ifndef MODEL_HPP
#define MODEL_HPP
#include "GenericModel.hpp"
#include <libxml/parser.h>
#include <libxml/tree.h>
class GenericModel;
class Model : public GenericModel{
public:
Model();
~Model();
void Render();
bool LoadModelOBJ(char *);
bool LoadModelXML(char *);
bool LoadTexture(char *);
private:
GLuint textureID;
GLuint texture;
bool modelLoaded;
bool textureLoaded;
GLuint textureBuffer;
bool OpenOBJModel(char*, std::vector<glm::vec3> & , std::vector<glm::vec2> & , std::vector<glm::vec3> & );
bool OpenXMLModel(char *filename, std::vector<glm::vec3> & vertOut, std::vector<glm::vec2> & uvOut, std::vector<glm::vec3> & normalOut);
};
#endif
第三
#ifndef LIGHT_OBJECT_HPP
#define LIGHT_OBJECT_HPP
#include "GenericModel.hpp"
class GenericModel; //PROBLEM
class LightObject: public GenericModel {
public:
LightObject();
~LightObject();
void Render();
glm::vec3 GetLight();
void SetLight(glm::vec3);
private:
glm::vec3 lightIntenzity;
};
#endif
当我尝试编译它们时,我收到错误
LightObject.hpp:9:27:错误:无效使用不完整类型'class GenericModel' class LightObject:public GenericModel { ^ LightObject.hpp:7:7:错误:'类GenericModel'的前向声明 class GenericModel;
如果我删除了前向声明,则会出现新错误:
LightObject.hpp:9:40:错误:'{'标记之前的预期类名 class LightObject:public GenericModel {
这让我非常困惑,因为它没有Model类的问题,这是以相同的方式完成的。包含前向声明。有人能指出我正确的方向吗?提前致谢! (BTW Base对象只是ID)
答案 0 :(得分:0)
其中一个包括LightObject.hpp:
#include "GenericShader.hpp"
#include "BaseObject.hpp"
#include "Scene.hpp"