我創建類電平的構造,但b口正在收到錯誤消息進行如下的:未定義參考構造函數C++
D:\downloads\cocos2d-2.0-x-2.0.4\cocos2d-2.0-x-2.0.4\armadillo\proj.android/jni/../../Classes/HelloWorldScene.cpp:43: undefined reference to `Levels::Levels()'
D:\downloads\cocos2d-2.0-x-2.0.4\cocos2d-2.0-x-2.0.4\armadillo\proj.android/jni/../../Classes/HelloWorldScene.cpp:44: undefined reference to `Levels::getCachedDataFromFile(std::string)'
代碼:
bool HelloWorld::init()
{
if (!CCLayer::init())
{
return false;
}
_levels = new Levels();
_levels->getCachedDataFromFile("\mnt\sdcard\levels.json");
return true;
}
我調用此方法在HelloWorld.cpp文件中的構造函數中。我在包含在HelloWorld.cpp中的HelloWorld.h中包含了Levels.h文件。
我將不勝感激,如果任何人可以幫助我,因爲我是初學者cpp。
我已經包含在頭文件中的方法和構造器,你可以在下面的代碼檢查:
#include "Box2d.h"
#include "cocos2d.h"
using namespace cocos2d;
#ifndef LEVELS_H_
#define LEVELS_H_
class Levels: public b2ContactListener {
public:
Levels();
~Levels();
void BeginContact(b2Contact *contact);
void EndContact(b2Contact *contact);
void preSolve(b2Contact* contact, const b2Manifold* oldManifold);
void postSolve(b2Contact* contact, const b2ContactImpulse* impulse);
void getCachedDataFromFile(string filePath);
private:
// const string LEVEL_FILE_NAME = "levels.json";
};
#endif /* LEVELS_H_ */
Level.cpp
#include "Levels.h"
#include <android/log.h>
#define LOG_TAG "levels"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
Levels::Levels() {
}
Levels::~Levels() {
}
void Levels::BeginContact(b2Contact *contact) {
}
void Levels::EndContact(b2Contact *contact) {
}
void Levels::getCachedDataFromFile(string filePath) {
unsigned long filesize = 0;
unsigned char* fileData = NULL;
std::string content, fullPath;
int i =1;
fullPath = CCFileUtils::sharedFileUtils()- > fullPathFromRelativePath(filePath.c_str());
fileData = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(),
"r", &filesize);
content.append((char*) fileData);
LOGD(content.c_str());
// if (languagesDocument.Parse <0> (content.c_str()).HasParseError()) {
// LOGD(languagesDocument.GetParseError());
//// CCLog(languagesDocument.GetParseError());
// }
//返回NULL; }
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OpenCV
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include ../../../projects/android-opencv/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
#Required for android log from jni code
LOCAL_LDLIBS += -llog -ldl
#Add path to OpenCV's header files
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../libs/Box2d \
../../../projects/android-opencv/sdk/native/jni/include/
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static c cocos_extension_static box2d_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions) \
$(call import-module,Box2D)
從'Level.h'中添加'getCachedDataFromFile'的聲明。當前信息不夠 – uba 2013-03-08 10:33:23
包含標題,其中定義了級別。而你並沒有創建Levels的構造函數。 – TheMathemagician 2013-03-08 10:35:08
你正在編譯/連接Level.cpp以及包含它的頭文件嗎? – simonc 2013-03-08 10:35:18