Board index » cppbuilder » CPP2007 E2015 Compiler cannot recognize (String) operator

CPP2007 E2015 Compiler cannot recognize (String) operator


2007-06-16 09:18:09 AM
cppbuilder23
I have an operator (String) -- apparently the compiler thinks its a
Cast...This was not a problem in cb4,5,6 or BDS2006.
planMne = (String)table.benPlanMne;
beneficiaryLine1= (String)table.benLine1;
beneficiaryLine2= (String)table.benLine2;
batchNumber = (String)table.benBatch;
}
[BCC32 Error] Benefic.cpp(98): E2015 Ambiguity between '_fastcall
System::AnsiString::AnsiString(const char *) at c:\program
files\codegear\rad studio\5.0\include\vcl\dstring.h:69' and '_fastcall
System::AnsiString::AnsiString(const System::AnsiString &) at c:\program
files\codegear\rad studio\5.0\include\vcl\dstring.h:70'
 
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

"ActuaryOne" < XXXX@XXXXX.COM >writes:
Quote
I have an operator (String) -- apparently the compiler thinks its a
Cast...This was not a problem in cb4,5,6 or BDS2006.
planMne = (String)table.benPlanMne;
beneficiaryLine1= (String)table.benLine1;
beneficiaryLine2= (String)table.benLine2;
batchNumber = (String)table.benBatch;
}
[BCC32 Error] Benefic.cpp(98): E2015 Ambiguity between '_fastcall
System::AnsiString::AnsiString(const char *) at c:\program
files\codegear\rad studio\5.0\include\vcl\dstring.h:69' and '_fastcall
System::AnsiString::AnsiString(const System::AnsiString &) at
c:\program files\codegear\rad studio\5.0\include\vcl\dstring.h:70'
Can you show more code? For example, which line is causing problems,
and what is the exact type of ... whatever it is that isn't working?
If you have an implicit conversion operator, you shouldn't need to
cast it. (You *are* casting it, but the cast may invoke your
conversion operator.)
But your post lacks far too many details for anyone to be able to
debug your program.
Also, the compiler is presumably better in CPP2007, so it's entirely
possible that your code depends on an old compiler bug that was
finally fixed. (It's possible they added a new bug too, but blaming
the compiler is the very last thing a programmer ought to do, as it
drains your motivation from debugging your own code, which is far more
likely to contain bugs.)
--
Chris (TeamB);
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

Here is the class operator declaration and some more code::
operator String() { return Str();} // Str() has a call to get(iu) in it
Quote
>>>
void BenClass::writeFrom(BenClass & table)
{
hash = (long)table.benHash ;
planMne = (String)table.benPlanMne;
beneficiaryLine1= (String)table.benLine1;
beneficiaryLine2= (String)table.benLine2;
batchNumber = (String)table.benBatch;
}
Quote
>>>
Seems like it should be easily duplicable...BTW CPP2007 is GREAT...we've
ordered 11 licenses...good job girls and boys!!!
"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
"ActuaryOne" < XXXX@XXXXX.COM >writes:

>I have an operator (String) -- apparently the compiler thinks its a
>Cast...This was not a problem in cb4,5,6 or BDS2006.
>planMne = (String)table.benPlanMne;
>beneficiaryLine1= (String)table.benLine1;
>beneficiaryLine2= (String)table.benLine2;
>batchNumber = (String)table.benBatch;
>}
>[BCC32 Error] Benefic.cpp(98): E2015 Ambiguity between '_fastcall
>System::AnsiString::AnsiString(const char *) at c:\program
>files\codegear\rad studio\5.0\include\vcl\dstring.h:69' and '_fastcall
>System::AnsiString::AnsiString(const System::AnsiString &) at
>c:\program files\codegear\rad studio\5.0\include\vcl\dstring.h:70'

Can you show more code? For example, which line is causing problems,
and what is the exact type of ... whatever it is that isn't working?

If you have an implicit conversion operator, you shouldn't need to
cast it. (You *are* casting it, but the cast may invoke your
conversion operator.)

But your post lacks far too many details for anyone to be able to
debug your program.

Also, the compiler is presumably better in CPP2007, so it's entirely
possible that your code depends on an old compiler bug that was
finally fixed. (It's possible they added a new bug too, but blaming
the compiler is the very last thing a programmer ought to do, as it
drains your motivation from debugging your own code, which is far more
likely to contain bugs.)

--
Chris (TeamB);
 

{smallsort}

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

Chris attached is a short project duplicating the error. Below is the
unit.cpp code
Quote
>>>>>>
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
class F1
{
public:
String Str();//this pulls data from the database
String strVal;
String strValx;
double currencyVal;
double currencyValx;
double doubleVal;
double doubleValx;
double operator * (const double x);
double operator / (const double x);
F1();
float floatVal;
float floatValx;
int columnNumber; // This is used by various pgms...usually is 0,1,2...
int displayColumn;
int intVal;
int intValx;
int length; // length of field
int fieldDecimals; // Data4 is the base class for Table class--use Table
in coding
int fieldLength;
long longVal;
long longValx;
operator char * ();
operator String() { return strVal;}
short shortVal;
short shortValx;
unsigned char byteVal;
unsigned char byteValx;
unsigned long uLongVal;
unsigned long uLongValx;
void operator=(const String x);
void operator=(const double x);
void operator+=(const double x);
void operator=(const int x);
void operator=(const long x);
void operator=(const short x);
void operator=(const bool x);
void operator=(const boolean x);
};
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
F1 x;
x.strVal = "Hello world";
String newString;
newString = (String)x;
}
//---------------------------------------------------------------------------
Quote
>>>>>>
"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
"ActuaryOne" < XXXX@XXXXX.COM >writes:

>I have an operator (String) -- apparently the compiler thinks its a
>Cast...This was not a problem in cb4,5,6 or BDS2006.
>planMne = (String)table.benPlanMne;
>beneficiaryLine1= (String)table.benLine1;
>beneficiaryLine2= (String)table.benLine2;
>batchNumber = (String)table.benBatch;
>}
>[BCC32 Error] Benefic.cpp(98): E2015 Ambiguity between '_fastcall
>System::AnsiString::AnsiString(const char *) at c:\program
>files\codegear\rad studio\5.0\include\vcl\dstring.h:69' and '_fastcall
>System::AnsiString::AnsiString(const System::AnsiString &) at
>c:\program files\codegear\rad studio\5.0\include\vcl\dstring.h:70'

Can you show more code? For example, which line is causing problems,
and what is the exact type of ... whatever it is that isn't working?

If you have an implicit conversion operator, you shouldn't need to
cast it. (You *are* casting it, but the cast may invoke your
conversion operator.)

But your post lacks far too many details for anyone to be able to
debug your program.

Also, the compiler is presumably better in CPP2007, so it's entirely
possible that your code depends on an old compiler bug that was
finally fixed. (It's possible they added a new bug too, but blaming
the compiler is the very last thing a programmer ought to do, as it
drains your motivation from debugging your own code, which is far more
likely to contain bugs.)

--
Chris (TeamB);
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

The project was dnlded to download newsgroup...
"Chris Uzdavinis (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
"ActuaryOne" < XXXX@XXXXX.COM >writes:

>I have an operator (String) -- apparently the compiler thinks its a
>Cast...This was not a problem in cb4,5,6 or BDS2006.
>planMne = (String)table.benPlanMne;
>beneficiaryLine1= (String)table.benLine1;
>beneficiaryLine2= (String)table.benLine2;
>batchNumber = (String)table.benBatch;
>}
>[BCC32 Error] Benefic.cpp(98): E2015 Ambiguity between '_fastcall
>System::AnsiString::AnsiString(const char *) at c:\program
>files\codegear\rad studio\5.0\include\vcl\dstring.h:69' and '_fastcall
>System::AnsiString::AnsiString(const System::AnsiString &) at
>c:\program files\codegear\rad studio\5.0\include\vcl\dstring.h:70'

Can you show more code? For example, which line is causing problems,
and what is the exact type of ... whatever it is that isn't working?

If you have an implicit conversion operator, you shouldn't need to
cast it. (You *are* casting it, but the cast may invoke your
conversion operator.)

But your post lacks far too many details for anyone to be able to
debug your program.

Also, the compiler is presumably better in CPP2007, so it's entirely
possible that your code depends on an old compiler bug that was
finally fixed. (It's possible they added a new bug too, but blaming
the compiler is the very last thing a programmer ought to do, as it
drains your motivation from debugging your own code, which is far more
likely to contain bugs.)

--
Chris (TeamB);
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

ActuaryOne wrote:
Quote
F1 x;
x.strVal = "Hello world";
String newString;
newString = (String)x;
What's wrong with doing this?
newString = x;
That's why you wrote an auto-converter, isn't it?
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

That just an example.
char z[128];
lstrcpy(z,x)...would not work in your example...you' still need a String
operator...
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
ActuaryOne wrote:

>F1 x;
>x.strVal = "Hello world";
>String newString;
>newString = (String)x;

What's wrong with doing this?
newString = x;
That's why you wrote an auto-converter, isn't it?


 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

ActuaryOne wrote:
Quote
That just an example.
char z[128];
lstrcpy(z,x)...would not work in your example...you' still need a String
operator...
I would think what you want there is a char* operator.
Haven't tested this bit, but I'd be tempted to write
lstrcpy( z, x.c_str() );
and see what I get.
 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

Yep, you're right....we have one...the c_str() also works....Bob, are you
saying I do not need the (String) operator explicitly inthe following,
meaning that the compiler will recognize the target (newString) as a String
, and automaticatically assign using the (String)x operator???
In other words,
newString = x;
would work....
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
ActuaryOne wrote:

>That just an example.
>char z[128];
>lstrcpy(z,x)...would not work in your example...you' still need a String
>operator...

I would think what you want there is a char* operator.

Haven't tested this bit, but I'd be tempted to write
lstrcpy( z, x.c_str() );
and see what I get.


 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

Damn, you're right...I just tested it....that's one smart compiler...thanks
BOB.
"ActuaryOne" < XXXX@XXXXX.COM >wrote in message
Quote
Yep, you're right....we have one...the c_str() also works....Bob, are you
saying I do not need the (String) operator explicitly inthe following,
meaning that the compiler will recognize the target (newString) as a
String , and automaticatically assign using the (String)x operator???
In other words,
newString = x;

would work....

"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>ActuaryOne wrote:
>
>>That just an example.
>>char z[128];
>>lstrcpy(z,x)...would not work in your example...you' still need a String
>>operator...
>
>I would think what you want there is a char* operator.
>
>Haven't tested this bit, but I'd be tempted to write
>lstrcpy( z, x.c_str() );
>and see what I get.
>
>


 

Re:CPP2007 E2015 Compiler cannot recognize (String) operator

ActuaryOne wrote:
Quote
Damn, you're right...I just tested it....that's one smart compiler...thanks
BOB.
It was Chris that said it.
(Thanks Chris)