BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wrong overloaded function called - Cpp Builder 5

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Hopeton
Guest





PostPosted: Fri Aug 15, 2003 6:39 pm    Post subject: Wrong overloaded function called - Cpp Builder 5 Reply with quote



I have a Delphi component that I want to convert to C++ builder 5. I am
creating a new package in c++ builder 5 where the source files are the .pas
files. Everthing compiles fine and I can install the package, etc.
However, the C++ builder version calls the wrong overloaded functions. It
always seems to call the first declared function, regardless of the
arguments that are passed.

Does anyone knows why this happens? Is there some compiler directive that I
might be missing on the Delphi or C++ end?


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Aug 15, 2003 7:34 pm    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote




"Hopeton" <hopeton (AT) palmsoft (DOT) com> wrote

Quote:
I have a Delphi component that I want to convert to C++
builder 5. I am creating a new package in c++ builder 5
where the source files are the .pas files. Everthing compiles
fine and I can install the package, etc. However, the C++
builder version calls the wrong overloaded functions. It
always seems to call the first declared function, regardless
of the arguments that are passed.

Please provide a sample of actual code that shows what it happening. What
do the original Pascal declarations look like? What does the generated C++
header file(s) look like? What does the calling C++ code look like?


Gambit



Back to top
Hopeton
Guest





PostPosted: Fri Aug 15, 2003 11:19 pm    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote



It actually happens from inside the delphi unit, but runs fine under delphi.
Example:

Function SetDates(StartDate,EndDate: TDateTime): boolean; overload;
Function SetDates(StartDate: TDateTime; Duration: Integer): boolean;
overeload;


Procedure SomeOtherMethod;
begin
if SetDates(Now, 20) then
showmessage('EndDate calculated and set');
end;

When SomeOtherMethod executes in Delphi, the second SetDates method is
correctly called as the second argument is an integer. However, running the
same code, compiled under C++ builder 5 (using the exact pas files) executes
incorrectly. The first SetDates method is called, even though the second
argument is clearly an integer, not a TDateTime.



"Remy Lebeau (TeamB)" <gambit47 (AT) yahoo (DOT) com> wrote

Quote:

"Hopeton" <hopeton (AT) palmsoft (DOT) com> wrote in message
news:3f3d28e6$1 (AT) newsgroups (DOT) borland.com...
I have a Delphi component that I want to convert to C++
builder 5. I am creating a new package in c++ builder 5
where the source files are the .pas files. Everthing compiles
fine and I can install the package, etc. However, the C++
builder version calls the wrong overloaded functions. It
always seems to call the first declared function, regardless
of the arguments that are passed.

Please provide a sample of actual code that shows what it happening. What
do the original Pascal declarations look like? What does the generated
C++
header file(s) look like? What does the calling C++ code look like?


Gambit





Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Aug 16, 2003 3:29 am    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote


"Hopeton" <hopeton (AT) palmsoft (DOT) com> wrote


Quote:
Function SetDates(StartDate,EndDate: TDateTime): boolean; overload;
Function SetDates(StartDate: TDateTime; Duration: Integer): boolean;
overeload;

I would expect those functions to produce an ambiquity error. I'm surprised
the compile even allowed the code to finish compiling, let alone to run.
You are passing a value as '20' as the second parameter. '20' can be
converted to both an 'int' and a 'TDateTime' (TDateTime has an int
contructor), but you're not telling the compiler what it should be. You
should cast your value to the appropriate type in order to tell the compiler
which actual function to call, ie:

SetDates(Now, Integer(20))
SetDates(Now, TDateTime(20))


Gambit



Back to top
Torsten Franz (TeamBeer)
Guest





PostPosted: Mon Aug 18, 2003 11:42 am    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote

Quote:
Function SetDates(StartDate,EndDate: TDateTime): boolean; overload;
Function SetDates(StartDate: TDateTime; Duration: Integer): boolean;
overeload;

I would expect those functions to produce an ambiquity error. I'm

Why?

20 -> int , no conversion needed
20 ->TDateTime conversion needed (via ctor)

so best match is the version taking an int, no ambiquity.

Torsten




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Aug 18, 2003 6:02 pm    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote


"Torsten Franz (TeamBeer)" <Torsten_Franz (AT) REMOVE (DOT) agilent.com> wrote in
message news:3f40bb94$1 (AT) newsgroups (DOT) borland.com...

Quote:
20 -> int , no conversion needed
20 ->TDateTime conversion needed (via ctor)

It doesn't matter whether a conversion is needed or not. The fact that a
conversion *can* occur should be ambiquious enough. 20 can be passed to
TDateTime directly. So what is there to tell the compiler which one to call
if it can go both ways to begin with?


Gambit


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com)[/url].
Version: 6.0.510 / Virus Database: 307 - Release Date: 8/14/03



Back to top
Torsten Franz (TeamBeer)
Guest





PostPosted: Tue Aug 19, 2003 6:39 am    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote

Quote:
20 -> int , no conversion needed
20 ->TDateTime conversion needed (via ctor)

It doesn't matter whether a conversion is needed or not. The fact

The fact is, it should matter.

Quote:
that a conversion *can* occur should be ambiquious enough. 20 can be
passed to TDateTime directly. So what is there to tell the compiler
which one to call if it can go both ways to begin with?

Of course one can specify the intended type, but this doesn't help one to
understand
the reasons why the compiler chooses to call the wrong funtion in the first
place.

Torsten



Back to top
Torsten Franz (TeamBeer)
Guest





PostPosted: Tue Aug 19, 2003 6:55 am    Post subject: Re: Wrong overloaded function called - Cpp Builder 5 Reply with quote

Quote:
It doesn't matter whether a conversion is needed or not. The fact
that a conversion *can* occur should be ambiquious enough. 20 can be
passed to TDateTime directly. So what is there to tell the compiler
which one to call if it can go both ways to begin with?

What about this

void Func(int n){};
void Func(double d){};

....
Func(1.0d);

Which function should be called here?
Should the compiler flag the call ambiguous because a conversion
from double to int is possible?

No. The compiler needs to call the double version. Always.

The same for Func(1); Now the int version call is needed.
No ambiguity

If the observation of the OP is right then I would call this a compiler bug.

Torsten



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.