简体   繁体   English

尝试访问“常量类LHContactInfo”时的前向声明错误

[英]forward declaration of 'const class LHContactInfo' error when try to access it property

I have two c++ class bellow. 我有两个下面的C ++类。 I want get LHContactInfo property from LHSceneSubclass but I can get nothing.So How can I do with this? 我想从LHSceneSubclass获取LHContactInfo属性,但是我什么也得不到。那么我该怎么办?

 #ifndef __LEVELHELPER_API_CONTACT_INFO_H__ #define __LEVELHELPER_API_CONTACT_INFO_H__ #include "LHConfig.h" #if LH_USE_BOX2D #include "cocos2d.h" class b2Contact; using namespace cocos2d; class LHContactInfo { public: LHContactInfo(); virtual ~LHContactInfo(); Node* nodeA; Node* nodeB; std::string nodeAShapeName; std::string nodeBShapeName; int nodeAShapeID; int nodeBShapeID; Point contactPoint; float impulse; b2Contact* box2dContact; }; #endif #endif //__LEVELHELPER_API_CONTACT_INFO_H__ #include "LHContactInfo.h" #if LH_USE_BOX2D #include "Box2d/Box2d.h" LHContactInfo::LHContactInfo(){ nodeA = NULL; nodeB = NULL; box2dContact = NULL; } LHContactInfo::~LHContactInfo(){ nodeA = NULL; nodeB = NULL; box2dContact = NULL; } #endif 

 #ifndef __LH_SCENE_SUBCLASS_H__ #define __LH_SCENE_SUBCLASS_H__ #include "cocos2d.h" #include "LevelHelper2API.h" class LHContactInfo; class LHSceneSubclass : public LHScene { public: static cocos2d::Scene* createScene(); LHSceneSubclass(); virtual ~LHSceneSubclass(); bool initWithContentOfFile(const std::string& plistLevelFile); virtual bool shouldDisableContactBetweenNodes(Node* nodeA, Node* nodeB); virtual void didBeginContact(const LHContactInfo& contact); virtual void didEndContact(const LHContactInfo& contact); }; #endif // __LH_SCENE_SUBCLASS_H__ //file.cpp void LHSceneSubclass::didBeginContact(const LHContactInfo& contact){ if(contact.nodeA->getName() == "box1"){// error invalid use of incomplete type 'const class LHContactInfo' } } void LHSceneSubclass::didEndContact(const LHContactInfo& contact){ CCLOG("DIDENDCONTACT...\\n"); } 

I want to do like contact.nodeA from LHContactInfo in didBeginContact function but compile error ->error invalid use of incomplete type 'const class LHContactInfo' 我想在didBeginContact函数中像LHContactInfo的contact.nodeA一样,但是编译错误->错误使用不完整类型'const class LHContactInfo'

Note:: - Compile with android NDK 10c 注意::-使用android NDK 10c进行编译

The class LHContactInfo is only declared (ie, know by name), due to your forward declaration. 由于您的前向声明,仅声明了LHContactInfo类(即,按名称知道)。 However, the compiler needs the class definition. 但是,编译器需要类定义。 You need to include the file containing the class definition. 您需要包括包含类定义的文件。

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

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