基类未定义 [英] Base class undefined

查看:134
本文介绍了基类未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的代码会产生错误

My code below generates the error

'WorldObject':[未定义基类(从德语翻译)]

'WorldObject': [Base class undefined (translated from german)]

这是为什么?这是产生此错误的代码:

Why is this? Here is the code which produces this error:

#pragma once

#ifndef _PROJECTILOBJECT_H_
#define _PROJECTILOBJECT_H_

#include "GameObjects.h"
class WorldObject;
class ProjectilObject: public WorldObject
{
public:
    ProjectilObject(IGameObject* parent,int projectiltype);

    void deleteyourself();
protected:
virtual void VProcEvent( long hashvalue,    std::stringstream &stream);
    virtual void VInit();
    virtual void VInitfromStream( std::stringstream &stream     );
    virtual void VonUpdate();
    virtual void VonRender();
private:
    vec3 vel;

    float lifetime;
    float lifetimeend;

    vec3 target;

    int m_projectiltype;
};

#endif

这是WorldObject类中的代码文件:

Here is the code file from the WorldObject class:

#pragma once

#ifndef _GAMEONJECTCODE_H_
#define _GAMEONJECTCODE_H_

#include "IGameObject.h"
#include "Sprite.h"
#include "GamePath.h"
#include "HashedString/String.h"
#include "IAttribute.h"
#include "CharacterObjects.h"

...

class WorldObject: public IGameObject, public MRenderAble
{
public:
    WorldObject(IGameObject* parent);
    virtual bool IsDestroyAble();
    virtual bool IsMageAble();
    virtual bool IsRenderAble();
protected:
    virtual void VProcEvent( long hashvalue, std::stringstream &stream);
    virtual void VonUpdate();
    virtual void VonRender();
    virtual void VInit() =0;
    virtual void VInitfromStream( std::stringstream &stream ) =0;
    virtual void VSerialize( std::stringstream &stream );

    vec3 poscam;    
};

...

#endif

此文件中还有其他一些类,但是我认为它们没有关系.也许有一个我没有看到的小错误,但我不明白为什么会产生此错误.当您需要更多代码时,请随意.

There are some other classes in this file but they shouldn't matter, I don't think. Maybe there is a tiny error I didn't saw but I don't understand why this error is produced. When you need more of the code feel free.

推荐答案

如果您有任何在ProjectilObject.h之前包含GameObjects.h的源文件,或者不直接包含ProjectilObject.h的源文件,则编译器将首先找到的声明.在知道WorldObject是什么之前,先通过ProjectilObject中的包含内容访问ProjectilObject.这是因为GameObjects.h首先包含ProjectilObject.h,然后声明WorldObject.在这种情况下,ProjectilObject.h中存在的GameObjects.h包含将无法工作,因为已经定义了_GAMEONJECTCODE_H_.

If you have any source file that includes GameObjects.h before ProjectilObject.h or does not include ProjectilObject.h directly, then the compiler will first find the declaration of ProjectilObject through the include in GameObjects.h before knowing what WorldObject is. That is because GameObjects.h first includes ProjectilObject.h and then declares WorldObject. In that case the include of GameObjects.h present in ProjectilObject.h won't work because _GAMEONJECTCODE_H_ will be already defined.

为避免这种情况,请确保在源文件中包含ProjectilObject.h而不是GameObjects.h,或者在使用时使用

To avoid this, either be sure to include ProjectilObject.h instead of GameObjects.h in your source file, or use forward declarations.

这篇关于基类未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆