gpt4 book ai didi

android - C++ 中对构造函数的 undefined reference

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:37 25 4
gpt4 key购买 nike

我正在创建类级别的构造函数,如下所示,但是我收到一条错误消息:

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.h 中包含了 Levels.h 文件,我将其包含在 HelloWorld.cpp 中。

如果有人能帮助我,我将不胜感激,因为我是 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_ */

关卡.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;

安卓.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)

最佳答案

你实现构造函数了吗?在 Levels.cpp 中添加:

Levels::Levels()
{
// constructor code here …
}

对于析构函数也是如此:

Levels::~Levels()
{
// destructor code here …
}

关于android - C++ 中对构造函数的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15291878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com