c++ - C++ 中的未知类型错误

标签 c++ xcode cinder

这是怎么回事?

#include "MyClass.h"

class MyOtherClass {
  public:
    MyOtherClass();
    ~MyOtherClass();

    MyClass myVar; //Unknown type Error
};

突然间,当我包含 .h 并写入 var Xcode 时,给我带来了很多错误……还有未知类型错误。

.h 就在那里,怎么会不知道呢?

这是与示例中的 MyClass.h 相对应的 NodeButton.h 文件

#pragma once

#include "cinder/Vector.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/Texture.h"
#include "cinder/Color.h"
#include "cinder/ImageIo.h"
#include "cinder/Timeline.h"
#include "cinder/app/AppBasic.h"
#include "cinder/App/App.h"

#include "Node.h"
#include "CursorMano.h"

using namespace ci;
using namespace ci::app;
using namespace std;
using namespace is;

typedef boost::shared_ptr<class NodeButton> NodeButtonRef;


class NodeButton  : public Node2D 
{
    public:
        NodeButton (CursorMano *cursor, string imageUrl, bool fadeIn = false, float delay = 0.0f);
        virtual ~NodeButton ();

        //methods
        void update( double elapsed );
        void draw();
        void setup();

        //events
        bool mouseMove( ci::app::MouseEvent event );

        //vars
        CursorMano      *mCursor;
        gl::Texture     mImageTexture;
        Anim<float>     mAlpha = 1.0f;
        bool            mSelected = false;

    private:
};

下面是 CursorMano.h 的内容,对应于示例中的 MyOtherClass.h。

#pragma once

#include <list>
#include <vector>

#include "cinder/app/AppBasic.h"
#include "cinder/qtime/QuickTime.h"
#include "cinder/gl/Texture.h"
#include "cinder/Vector.h"

#include "NodeButton.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class CursorMano {
    public:
        CursorMano (AppBasic *app);
        ~CursorMano ();

        void    mueveMano(Vec2i);
        void    update();
        void    draw();
        void    play(int button);
        void    reset(int button);

        Vec2i   mMousePos;
        NodeButton                  mButtonCaller; //this gives the unknow type error

    private:
        AppBasic                    *mApp;
        gl::Texture                 mFrameTexture;
        qtime::MovieGl              mMovie;
        int                         mIdButton;
};

最佳答案

你的头文件有一个循环依赖。

NodeButton.h定义 NodeButtonCursorMano.h需要包含以便编译器可以看到 NodeButton 的定义但是NodeButton.h本身包括 CursorMano.h .

您需要使用前向声明来打破这种循环依赖。

NodeButton.h您只需使用指向 CursorMano 的指针所以你不需要包括 CursorMano.h只需在 using 命名空间声明之后转发声明类。

using namespace std;
using namespace is;

class CursorMano;

关于c++ - C++ 中的未知类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9171307/

相关文章:

C++ 和进程内存保护

java - native a方法中的参数传递

xcode - 如何在 Xcode 4 的运行脚本构建阶段中使用 sudo?

ios - React-Native xcrun : error: Failed to locate 'instruments' in Xcode 13

c++ - OpenGL:如何根据相机距离对点进行排序?

c++ - 将 itkImage 保存为 DICOM 时未写入图像位置/方向

c++ - QPlainTextEdit 上的 Qt 代码编辑器 如何选项卡代码

objective-c - Command/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang++ 失败,退出代码为 1

c++ - 如何使用 InterfaceGL 设置默认值?

c++ - C++/Cinder如何让窗口大小和打开的图片一样