2016-11-12 57 views
0

我的階段是這樣的:傳遞一個結構作爲陣列和存儲

enum Gait_cycle_states { 
HEEL_STRIKE, 
FLAT_FOOT, 
MID_STANCE, 
HEEL_OFF, 
TOE_OFF, 
MID_SWING 
}; 

我的結構是這樣的:

struct State { 
Gait_cycle_states current_state; 
uint8_t next_state; //index of the next state 

uint8_t ay_num_criteria; 
State_criterion *ay_criteria_for_state; 

unsigned int gy_num_criteria; 
State_criterion *gy_criteria_for_state; 
}; 

和我的功能看起來像這樣:

void initialize_FSM(State states_array[]){ 
//Heel strike---------------------------------------------------------- 

State heel_strike = { 
    .current_state = HEEL_STRIKE, 
    .next_state = 1, //the index of the next state 

    .ay_num_criteria = 1, 
    .ay_criteria_for_state = new State_criterion[1], 

    .gy_num_criteria = 2, 
    .gy_criteria_for_state = new State_criterion[2] 
}; 

//The features to look for in accel_y and gyro_y, and how old they can be to count (in ms) 
heel_strike.ay_criteria_for_state[0] = { NO_FEATURE, 150 }; 
heel_strike.gy_criteria_for_state[0] = { NEGATIVE_TROUGH, 150 }; 
heel_strike.gy_criteria_for_state[1] = { BREACHED_HIGH_THRESHOLD, 30 }; 

//putting the state we just configured into the state array 
states_array[0] = heel_strike; 
}; 

看來Visual Studio 2015不會讓我使用「。」將值分配給我的類型。或者以時尚的方式,我正在做它。

它扔我一堆或錯誤和警告是這樣的:

1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(123): error C2059: syntax error: '.' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(131): error C2143: syntax error: missing ';' before '}' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3927: '->': trailing return type is not allowed after a non-function declarator 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3484: syntax error: expected '->' before the return type 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3613: missing return type after '->' ('int' assumed) 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2146: syntax error: missing ';' before identifier 'ay_criteria_for_state' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2143: syntax error: missing ';' before '{' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2447: '{': missing function header (old-style formal list?) 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3927: '->': trailing return type is not allowed after a non-function declarator 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3484: syntax error: expected '->' before the return type 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3613: missing return type after '->' ('int' assumed) 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2086: 'int heel_strike': redefinition 
1> c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): note: see declaration of 'heel_strike' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2146: syntax error: missing ';' before identifier 'gy_criteria_for_state' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2143: syntax error: missing ';' before '{' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2447: '{': missing function header (old-style formal list?) 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3927: '->': trailing return type is not allowed after a non-function declarator 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3484: syntax error: expected '->' before the return type 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3613: missing return type after '->' ('int' assumed) 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2086: 'int heel_strike': redefinition 
1> c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): note: see declaration of 'heel_strike' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2146: syntax error: missing ';' before identifier 'gy_criteria_for_state' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2143: syntax error: missing ';' before '{' 
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2447: '{': missing function header (old-style formal list?) 

可能有人請建議我可以做些什麼?

回答

1
State heel_strike = { 
    HEEL_STRIKE, 
    1, //the index of the next state 

    1, 
    new State_criterion[1], 

    2, 
    new State_criterion[2] 
}; 

你正在嘗試使用什麼被稱爲「指定初始值設定項」。它們是C語言的一個特性(自C99以來),不是標準C++的一部分。一些編譯器支持C++作爲擴展,但MSVC不支持。

+0

謝謝......你是對的。 –

+0

「*(我不相信它支持C代碼)*」它的確從VC++ 2013開始。但是,當編譯爲C時,從不編譯爲C++。 – ildjarn

+0

@ildjarn我刪除了括號。 –