Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StepperMotor.h: 'ISO C++ forbids initialization of member '_mode'' (and others) #1

Open
leggler opened this issue Dec 27, 2015 · 2 comments

Comments

@leggler
Copy link

leggler commented Dec 27, 2015

Hey Laurens!

I found your peace of code from the comments of http://www.instructables.com/id/BYJ48-Stepper-Motor/ . The code described there workes fine with me, but I agree that the object orientet options seems smarter, so thanks for the work! However, I cant get it running. When trying the example provided in the StepperMotor library, I get the following error. I checked if it was an import-issue (files in the wrong folder, etc.) but this does not seem to be the case...

Thanks! Lukas

Arduino: 1.0.6 (Mac OS X), Board: "Arduino Uno"
In file included from Example.ino:44:
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: ISO C++ forbids initialization of member '_mode'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: making '_mode' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: ISO C++ forbids in-class initialization of non-const static member '_mode'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: ISO C++ forbids initialization of member '_steps'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: making '_steps' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: ISO C++ forbids in-class initialization of non-const static member '_steps'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: ISO C++ forbids initialization of member '_delayMs'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: making '_delayMs' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: ISO C++ forbids in-class initialization of non-const static member '_delayMs'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: ISO C++ forbids initialization of member '_engineStep'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: making '_engineStep' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: ISO C++ forbids in-class initialization of non-const static member '_engineStep'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: ISO C++ forbids initialization of member '_currentStep'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: making '_currentStep' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: ISO C++ forbids in-class initialization of non-const static member '_currentStep'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: ISO C++ forbids initialization of member '_rotationDirection'
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: making '_rotationDirection' static
/Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: ISO C++ forbids in-class initialization of non-const static member '_rotationDirection'

@LaurensHuizer
Copy link
Owner

Hi Lukas,

This is very strange... it seems like the Mac software version cannot handle the direct initialization of the variables.
Can you try the following:

Change StepperMotor.h and remove the values from the variables (you can copy & paste this):
int _mode;
int _steps;
int _delayMs;
int _engineStep;
int _currentStep;
int _rotationDirection

Next change StepperMotor.cpp and add the initial values to the constructor (you can copy & paste this):
StepperMotor::StepperMotor(int pinA, int pinB, int pinC, int pinD)
: BaseTimedElement()
{
_pinA = pinA;
_pinB = pinB;
_pinC = pinC;
_pinD = pinD;
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
setWaitTimeEvery(_delayMs);
_mode = 0;
_steps = -1;
_delayMs = 1;
_engineStep = 0;
_currentStep = 0;
_rotationDirection = 0;
}

@leggler
Copy link
Author

leggler commented Dec 29, 2015

Hey Laurens!

Thanks for your quick answer! It seems like this really is a mac/windows problem!

With the suggested code-changes it works perfectly (Note however that a semicolon is missing in the last line of StepperMotor.h changes, the last line should be "int _rotationDirection;" )

Thanks for the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants