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

在头文件timer.h中,我声明

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;
...
}

在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;

}

编译.cpp文件时,出现错误:
timer.cpp:7:错误:“。” token 之前的预期初始化程序

任何建议都会非常有帮助。

顺便说一句我用g++

最佳答案

您无需在静态成员中单独定义单个实例成员。

这应该足够了:

AndroidTimerModel::Resources AndroidTimerModel::ResData;

09-07 19:35