小编fil*_*pos的帖子

如何在c ++中初始化静态结构?

我已经设法初始化正确的任何基本类型的变量(即int,char,float等),但在声明一个复杂的变量时,我只能看到错误.

在头文件中,timer.hi声明

class AndroidTimerConcept {
...
private:
    //struct that holds the necessary info for every event
    struct Resources{
        timer_delegate_t membFunct;
        void *data;
        int size;
        millis_t time;
    };
    //declaring an array of 10 Resources structs
    static struct Resources ResData;
    static int best;
...
}
Run Code Online (Sandbox Code Playgroud)

在timer.cpp文件中

#include <iostream>
#include "timer.h"
using namespace std;


int AndroidTimerModel::best=1000;
struct Resources AndroidTimerModel::ResData.size; //line 17!!
//constructor that initializes all the necessary variables

AndroidTimerModel::AndroidTimerModel()
{
    signal(SIGALRM,signalHandler);

    for(int i=0; i<MAX_EVENTS; i++)
    {
        //ResData.data=NULL;
        ResData.size=-1;
        //ResData.time=-1;
    }

    best=1000;

}
Run Code Online (Sandbox Code Playgroud)

在编译.cpp文件时,我收到错误:timer.cpp:7:错误:'.'之前的预期初始化程序.代币 …

c++ static struct initialization member

9
推荐指数
3
解决办法
3万
查看次数

在android NDK中包含本地头文件时的未定义引用

我构建了一个简单的android应用程序,它使用ndk和JNI.该应用程序具有onw .cpp(debugTest.cpp)文件,该文件用于将java和c ++与jni和另一个.c(javaEssentials.c)文件与其标头(javaEssentials.h)链接.当我在.cpp文件中包含.c文件(#include"javaEssentials.c")时,编译时不会报告错误.当我在.cpp文件中包含头文件时,编译器报告.c文件所具有的函数的未定义引用错误.这是一个真正奇怪的问题,我无法理解为什么会发生这种情况.像往常一样,我在.c文件中有一个包含头文件的声明.

我的android.mk是:

# build file written to describe the C and C++ source files to the Android NDK

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := debugTest
LOCAL_SRC_FILES := debugTest.cpp

include $(BUILD_SHARED_LIBRARY)
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?

java-native-interface android header include android-ndk

1
推荐指数
1
解决办法
3919
查看次数