Ошибка неизвестного типа в C++
Что здесь происходит?
#include "MyClass.h"
class MyOtherClass {
public:
MyOtherClass();
~MyOtherClass();
MyClass myVar; //Unknown type Error
};
Внезапно, когда я включаю.h и пишу, что var Xcode выдает мне массу ошибок... а также неизвестную ошибку типа.
Как это может быть неизвестно, когда.h включен прямо там?
Вот файл 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:
};
А вот содержимое 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;
};
2 ответа
You have a circular dependency of your header files.
NodeButton.h
определяет NodeButton
класс который CursorMano.h
needs to include so that compiler can see definition for NodeButton
но NodeButton.h
itself includes CursorMano.h
,
You will need to use forward declarations to break this circular dependency.
В 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.
using namespace std;
using namespace is;
class CursorMano;
It's probably a result of the circular dependency between you two header files (NodeButton
включает в себя CursorMano
а также CursorMano
включает в себя NodeButton
). Попробуйте удалить #include "CursorMano.h"
in NodeButton.h and add class CursorMano;
before your NodeButton
декларация.