[sword-devel] osis2mod linking bug
DM Smith
dmsmith555 at yahoo.com
Fri Sep 5 08:20:00 MST 2008
DM Smith wrote:
> I tried the following:
> key = module++;
> and I got surprising results. It did the post increment before the
> assignment! Semantically, this is wrong!
> Looking into it the post-increment operator is not defined and because
> of that the pre-increment operator is used.
> Here is a post increment operator:
> SWKey& operator ++(int /*unused*/) { SWKey temp = *this; increment(1);
> return temp; }
> Likewise for post decrement:
> SWKey& operator --(int /*unused*/) { SWKey temp = *this; decrement(1);
> return temp; }
> IIRC, post-increment was added to C++ 2.0.
Couple of corrections:
In SWKey, the post increment is defined but the pre-increment is not.
The pre-increment does not have a parameter.
My version of the post-increment should have returned SWKey not SWKey&.
Here are the appropriate, semantically correct implementations:
SWKey &operator ++() { increment(1); return *this; } \
SWKey operator ++(int) { SWKey temp = *this; increment(1); return
temp; } \
SWKey &operator --() { decrement(1); return *this; } \
SWKey operator --(int) { SWKey temp = *this; decrement(1); return temp; }
More information about the sword-devel
mailing list