const类LHContactInfo'尝试访问该属性时出错
forward declaration of 'const class LHContactInfo' error when try to access it property
下面我有两个c++类。我想从lhscenessubclass中获取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");
}
我想做喜欢的接触。nodeA从LHContactInfo在didBeginContact函数,但编译错误->错误无效使用不完整类型'const类LHContactInfo'
注意::-编译android NDK 10c
由于您的前向声明,类LHContactInfo
仅被声明(即通过名称知道)。然而,编译器需要类定义。您需要包含包含类定义的文件。
相关文章:
- 通过指向指针数组的指针访问子类的属性
- 使用内存地址访问结构的属性值
- 使用 CTRP 时,是否访问访问父构造函数 UB 中的子属性?
- 如何从传递到对象的对象内部访问对象的类属性?
- 如何使用 pybind 访问结构的属性?
- OpenCV Tracker 属性访问在 ARM 上因 SEGFAULT 而失败,但在 X86_64 中工作
- 如何使用指针从另一个类访问属性
- 让 Redhawk 组件访问另一个组件的属性
- 父级的子属性 - 访问权限
- 访问除main.cpp之外的.cpp文件中的QMLEngine/rootObject属性
- Nan::ObjectWrap to Napi::Object Wrap 无法访问 JavaScript 中的属性
- 对象属性同级访问
- 访问属性或使用 getter 方法
- 具有可移动节点、可访问属性和可靠ID的C++图
- 单声道嵌入:如何在 C/C++ 中访问属性的类型
- 访问属性树中的多值键
- 何时使用 " . " 或 " -> " 运算符访问属性或成员函数?
- Qt c++访问属性
- 如何从实体组件系统的子类中访问属性
- 无法访问属性 c++