我已經設法初始化正確的任何基本類型的變量(即int,char,float等),但是當聲明一個複雜的變量時,所有我能看到的都是錯誤。如何在C++中初始化一個靜態結構?
在頭文件timer.hi編譯.cpp文件時聲明
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;
}
內我得到的錯誤: timer.cpp:7:錯誤:'。'之前的預期初始化器令牌
任何建議都會非常有幫助。
順便說一句,我使用G ++
你的鏈接不再工作,雖然你的答案仍然存在對有同樣問題的人有價值。你能更新它嗎? – VisorZ 2016-09-16 08:07:47
我更新了一個不太可能腐爛的鏈接,並且在這個問題中包含了一個摘錄。 – BeeOnRope 2016-09-19 16:42:49