blackmamba591
blackmamba591

Reputation: 161

Passing a struct as an array and storing

My phase looks like this :

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

My struct looks like this :

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

and my function looks like this :

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

It seems Visual studio 2015 is not letting me assign the value to my types using "." or in the fashion, I am doing it.

It is throwing me a bunch or error and warnings like this :

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?)

could someone please suggest me what could be done?

Upvotes: 0

Views: 272

Answers (1)

Igor Tandetnik
Igor Tandetnik

Reputation: 52471

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

    1,
    new State_criterion[1],

    2,
    new State_criterion[2]
};

What you are trying to use is known as "designated initializers". They are a feature of C language (since C99), not part of standard C++. Some compilers support it for C++ as an extension, but MSVC does not.

Upvotes: 1

Related Questions