HP aC++/HP C A.06.25 Programmer's Guide
Overloaded Operations ++ and --
You must use the overloaded operations ++ and -- correctly. These operations require
a member function with one argument. If the function has no argument, a warning is
issued and a postfic is assumed in HP C++. In HP aC++, the inconsistency between
the overloaded function usage and definition is considered an error. To avoid this error,
change the class definition so that each overloaded function definition has the correct
number of arguments.
Example:
class T {
public:
T();
const T& operator++ ();
};
int main () {
T t;
t++;
}
Compiling the above code with HP C++ generates the following warning:
CC: "pre.C", Line 8: warning: prefix ++/-- used as postfix
(anachronism) (935)
Compiling the code with HP aC++ generates an error like the following:
Error 184: File “pre.C”, Line 8
Arithmetic or pointer type expected for operator ‘++’; type found was ‘T’.
To compile the code with HP C++ or HP aC++ use the following class definition:
class T {
public:
T();
const T& operator++ (); // prefix old style postfix definition
const T& operator++ (int); // postfix
};
Reference Initialization
Illegal reference initialization is no longer allowed. In HP C++, a warning is generated
stating that the initializer for a non-constant reference is not an lvalue (anachronism).
In HP aC++, an illegal initialization of a reference type generates an error and the
program does not compile. To avoid this error, use a constant reference.
Example:
void f() {
char c = 1;
int & r = c;
}
Compiling the above code with HP C++ generates the following warning:
C: “nonConstRef.C”, line 6: warning: initializer for non-const
reference not an lvalue (anachronism) (235)
284 Migrating from HP C++ (cfront) to HP aC++