HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

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)
Compiling the code with HP aC++ generates an error like the following:
Error: File nonConstRef.C, Line 6
Type mismatch; cannot initialize a int & with a char.
Try changing int & to const int &.
To successfully compile with both compilers, make the following changes to the code:
void f() {
char c = 1;
const int & r = c;
}
Using operator new to Allocate Arrays
In HP C++, operator new is called to allocate memory for an array. In HP aC++,
operator new [] is called to allocate memory for an array.
Example:
The following code compiles without error on HP C++.
typedef char CHAR;
typedef unsigned int size_t;
typedef const CHAR *LPCSTR, *PCSTR;
typedef unsigned char BYTE;
void* operator new (size_t nSize, LPCSTR lpszFileName, int nLine);
static char THIS_FILE[] = mw2.C;
int main() {
BYTE *p;
Migration Considerations Related to Standardization 271