I have the source code
6 #include <Servo.h>
7
8 void test() { delay(500); }
9 #if 0
10 class mover {
11 public:
12 int H;
13 [glow=yellow,2,300] int V;[/glow]
14 mover() { H = 0; V = 0; }
15 }; // class mover
16 #endif
with the error message
sketch_oct09a:13: error: 'mover' was not declared in this scope
Given that this code is preceded by an #if 0 and the terminating #endif has not yet been seen, how is it possible to get an error message on line 13? The reason for line 8 is that subsequently it thinks that delay(), random(), etc. are not defined.
I am using 1.5.6-r2
The reason I temporarily deleted this code was the fact that I was getting another spurious error message
sketch_oct09a:13: error: variable or field 'Move' declared void
sketch_oct09a:13: error: 'mover' was not declared in this scope
sketch_oct09a:13: error: 'M' was not declared in this scope
sketch_oct09a:13: error: expected primary-expression before 'int'
sketch_oct09a:13: error: expected primary-expression before 'int'
from the declaration, on line 116:
116 void Move(mover & M, int H, int V)
117 {
118 if(M.H != H)
Note that there are no references to line 116 in the error messages; they all reference line 13, which is in the middle of the declaration of the class mover.
If I change the name of the function 'Move' to something random, like 'MoveZ', then the same messages occur, except they are complaining about MoveZ (so it is not a case where Move was a name that had some other definition).
Prior to adding the class definition and the Move function, this sketch compiled and ran perfectly. I was "growing it" from the original Servo Sweep example to something relevant to my project, which requires two-axis control. At the moment, the Move function moves the H servo, and then moves the V servo; the plan is to move H and V servos "concurrently", by choosing the steps required to get the two motors to move during each iteration, e.g., at an appropriate iteration of the loop, move servo H by 1, and at another iteration, perhaps the same one in which H was moved, move servo V by 1, continue until each has moved the chosen amount. This requires more sophisticated computations (such as according to some modular counting, so that at the end of the loop, V and H have moved the requisite amount. This was more than I needed to tackle right now, so I abstracted the moving to a separate function so I could rewrite its guts later). So I added the state object 'mover' and the function 'Move' and the world fell apart.
What I don't understand is how code within an #if 0 can possibly be seen by the compiler.
The current Move function traverses H from M.H to H, sets M.H to H, then traverses V from M.V to V, and sets M.V to V. Thus it will always move the platform at two right angles (H and V are the horizontal and vertical axes), whereas what I really want to get is a "smooth" panning motion in both axes. Or more like a DDE computation for a line drawn at an angle on a discrete pixel-based display. There will be quantization of the movement, not pure, smooth approximations, but my application does not require "smooth" motion. Just the illusion of smooth motion. For example, imagine a motion-capturing camera that only captures a frame after each iteration. That's not the problem domain, either, but is intended to convey that I understand the 1-degree quantization issue.
Note also that I have been using C++ for a couple decades, so I have some idea what to expect of a compiler. The behavior I am seeing is not only unexpected, it is nonsensical.
joe