b.g();

// Error?

}

The ambiguity in the example code is whether b is declared as:

A function with one argument (named p) returning an object of type B.

An object of type B initialized with a temporary object of type A.

HP C++ compiles this code successfully and assumes b is an object. Compiling the code with HP aC++ generates the following error:

Error: File “objDeclaration.c”, Line 5

Left side of ‘.’ requires a class object; type found was a function ‘B (A)’. Did you try to declare an object with a nested constructor call?

Such a declaration is interpreted as a function declaration B b(A) [File “objDeclaration.c, Line 4].

Modify the code as shown below to successfully compile it with both compilers.

struct A {A(int);};

struct B {B(const A &); void g();};

void

f(int p) {

 

 

 

B

b = A(p);

//

declaration

of object

b.g();

//

method call

 

}

 

 

 

 

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 () {

Tt;

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

216 Migrating from HP C++ (cfront) to HP aC++

Page 216
Image 216
HP C/aC++ for PA-RISC Software manual Overloaded Operations ++, Reference Initialization