HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)
NOTE: This feature may not be a part of the Standard in future revisions.
Also, you cannot convert const char * to char *in a conditional expression in this
context.
Example:
char *p = f() ? “A” : “B”;
In such a scenario, you must change the code.
Example:
const char *p = f() ? “A” : “B”;
or
char *p = const_cast(f() ? “A” : “B”);
Overload Resolution Ambiguity of Subscripting Operator
HP C++ and HP aC++ have different overload resolution models. When you migrate to
HP aC++, you may see an overload resolution ambiguity for the subscripting operator.
The following code illustrates the problem:
struct String {
char& operator[](unsigned);
operator char*();
// ...
};
void f(String &s) {
s[0] = ‘0’;
}
HP C++ accepts the above code, selecting String::operator[](unsigned) rather
than the user-defined conversion, String::operator char*(), followed by the
built-in operator[].
Compiling the code with HP aC++ produces the following error:
Error 225: “c.C”, line 8 # Ambiguous overloaded function call;
more than one acceptable function found. Two such functions
that matched were “char &String::operator [](unsigned int)”
[“c.C”, line 2] and “char &operator [](char *,int)”
[Built-in operator].
s[0] = ‘0’;
The error message appears because the compiler cannot choose between:
1. Not converting s, but converting 0 from type int to type unsigned int; this
implies using the user- provided subscript operator[]
2. Converting s to type char* (using the user-defined conversion operator), but not
converting 0; this corresponds to using the built-in subscript operator[].
262 Migrating from HP C++ (cfront) to HP aC++