简体   繁体   English

C ++中的未知类型错误

[英]unknown type error in C++

What is going on? 到底是怎么回事?

#include "MyClass.h"

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

    MyClass myVar; //Unknown type Error
};

Suddenly when I include the .h and write that var Xcode gives me tons of errors... and also the unknown type error. 突然,当我包含.h并写道var Xcode给了我很多错误......还有未知类型错误。

How can it be unknown when the .h is included right there? 当.h被包含在那里时怎么可能不知道?

Here is the NodeButton.h file which would correspond to the MyClass.h in the example 这是NodeButton.h文件,它对应于示例中的MyClass.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:
};

And here are the contents of CursorMano.h which would correspond to MyOtherClass.h in the example. 以下是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;
};

You have a circular dependency of your header files. 您具有头文件的循环依赖关系。

NodeButton.h defines NodeButton class which CursorMano.h needs to include so that compiler can see definition for NodeButton but NodeButton.h itself includes CursorMano.h . NodeButton.h定义了CursorMano.h需要包含的NodeButton类,以便编译器可以看到NodeButton定义,但NodeButton.h本身包含CursorMano.h

You will need to use forward declarations to break this circular dependency. 您将需要使用前向声明来打破此循环依赖项。

In NodeButton.h you just use an pointer to CursorMano so You do not need to include the CursorMano.h just forward declare the class after the using namespace declarations. NodeButton.h您只需使用指向CursorMano的指针,因此您不需要包含CursorMano.h只需在using namespace声明之后向前声明该类。

using namespace std;
using namespace is;

class CursorMano;

It's probably a result of the circular dependency between you two header files ( NodeButton includes CursorMano and CursorMano includes NodeButton ). 这可能是两个头文件之间循环依赖的结果( NodeButton包括CursorManoCursorMano包括NodeButton )。 Try removing the #include "CursorMano.h" in NodeButton.h and add class CursorMano; 尝试删除NodeButton.h中的#include "CursorMano.h"并添加class CursorMano; before your NodeButton declaration. NodeButton声明之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM