I’ve just solved a problem I had with code within a constructor. Although the problem is now solved, can anyone give me an explanation.
I had a working sketch and a class library. The sketch created an object (based on my class) in the declarations section (i.e. before the setup() bit). This worked fine until I added some code to the constructor, as soon as I did this the sketch wouldn’t even start. I solved the problem by adding a begin() section to the class and moving the code that was in the constructor to begin(). I then called the begin() from within the setup(). It all works fine again.
I’ve put code within other constructors before without problems, the only difference this time is that my code involved calls to multiple objects and other classes. Most of the stuff I normally add to constructors is just to initialise a few variables.
Whats the difference here?