向前声明' const class LHContactInfo'尝试访问它时出错属性

时间:2015-08-05 11:08:08

标签: c++ levelhelper

我有两个c ++类。我想从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");
}




我想在didBeginContact函数中执行来自LHContactInfo的contact.nodeA但编译错误 - >错误无效使用不完整类型' const类LHContactInfo'

注:: - 使用android NDK 10c编译

1 个答案:

答案 0 :(得分:1)

由于您的前瞻性声明,类LHContactInfo仅被声明(即,通过名称知道)。但是,编译器需要类定义。您需要包含包含类定义的文件。