未定义基类,但包含其标头

问题描述 投票:2回答:1

我在一个函数没有返回正确类型的地方遇到麻烦,因为没有定义一个类。我正在使用工厂模式。

我收到的两个错误消息是:

'return':无法从'DLA *'转换为'Layer *'

和:

'Layer':未定义基类(编译源文件src \ Layer.cpp)

并且对包含Layer.h的每个文件重复相同的错误消息。

这是我的从Layer继承的类看起来像(DLA.h):

#pragma once

#ifndef _DLA
#define _DLA

#include "ofMain.h" 
#include "ofxGui.h"
#include "Layer.h"

class DLA: public Layer
{
public:
    DLA();
    void setup();
    void update();
    void draw();

private:
};

#endif

这是我的Layer类头(Layer.h):

#pragma once

#ifndef _LAYER
#define _LAYER

#include "ofMain.h" 
#include "ofxGui.h"
#include "DLA.h"

enum SceneType
{
    Scene_None,
    Scene_Default,
    Scene_DLA,
};

class Layer
{

public:

    void setup();
    void update();
    void draw();
    static Layer *CreateSimulation(SceneType Type);


private:
};

#endif

失败的功能是该功能,位于Layer.cpp

Layer *Layer::CreateSimulation(SceneType Type)
{
    switch (Type)
    {
    case Scene_None:
    default:
        return nullptr;
    case Scene_DLA:
        return new DLA();
    }
}

我已经尝试了我在Stack Overflow上可以找到的所有与我有类似问题的东西,但是我看到有人建议使用非常微妙的代码缩进来解决此问题,所以我真的迷失了寻找问题所在的位置。] >

enter image description here

我在一个函数没有返回正确类型的地方遇到麻烦,因为没有定义一个类。我正在使用工厂模式。我收到的两个错误消息是:'return':无法...

c++ class oop inheritance factory
1个回答
1
投票

按现状显示,即使#pragma once(和其他)防护措施阻止了任何实际的“无限递归”,您的头文件也会引起circulardependence

© www.soinside.com 2019 - 2024. All rights reserved.