Technical article 100823

C++ compilation fails with "error: bad operand for ++: iterator".

OpenServer 5.0.0

Written · Last revised

Problem

I am compiling my C++ application and getting the error:

"class.C", line 14: error: bad operand for ++: iterator

The failure seems to relate to the code:

class iterator { public: iterator(const collection &aCollection); void start(); const baseObject *operator++(int); };

Cause

This problem highlights a problem in the version of cfront 3.0.2 that is used for the C++ compiler in SCO OpenServer Development System Release 5.0.

The cfront 3.0.2 preprocessor will reject the overloading of the operator++ function as used in the example above.

NOTE:     The overloading of C++ functions allows the same function name to
          be used more than once for different implementations, each
          implementation of the function being distinguished by either the
          type or number of its parameters.

Solution

By declaring the prefix operator++(), cfront 3.0.2 will correctly handle the postfix operator++(int). For example:

class iterator { public: iterator(const collection &aCollection); void start(); const baseObject *operator++(int); // postfix operator const baseObject *operator++(); //prefix operator };

This has been reported to SCO Engineering and is scheduled to be corrected in a future release of the C++ compiler.

From the Xinuos technical article database, record 100823. Reproduced with permission. The original is at www.sco.com/ta/100823, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.