473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Overload Resolution

I'm getting what I think is a bug in the way the VB compiler determines the
correct overloaded method to call. I have written a class to wrap
System.Configuaration.ConfigurationSettings with some type-safe methods -
for instance two methods are : -

Public Overloads Shared Function GetInt32(ByVal key As String, ByVal
defaultValue As Integer) As Integer
....
End Function

Public Overloads Shared Function GetInt32(ByVal key As String, ByVal style
As NumberStyles) As Long
....
End Function

(There are several other overloads but these are the two that are causing me
grief)

To me, the logical way to call this from my application class would be as
follows: -

Private Shared ReadOnly s_MyInteger As Integer =
ConfigurationSettings.GetInt32("IntegerKey", 0) 'This calls
GetInt32(String, NumberStyles)!!

However, when I do this, the compiler binds to the overload that takes a
NumberStyles parameter instead of the one that takes an integer! This seems
crazy to me as you would think the compiler would favour an exact match over
one that requires a conversion. Using CInt or the I suffix does not alter
this behaviour. The only work around is to declare a constant or a variable
with a suitable value and pass that instead: -

Private Const blankValue As Integer = 0
Private Shared ReadOnly s_MyInteger As Integer =
ConfigurationSettings.GetInt32("IntegerKey", blankValue) 'This calls
GetInt32(String, Integer) CORRECT!

Am I correct in thinking this is a compiler bug or am I missing some
subtlety in the resolution rules?

Regards,

Nick Hall
Nov 21 '05 #1
1 1025
OK did this in completely the wrong order by posting here and THEN checking
Google :-)

It would seem that this issue centres around the treatment of the value 0 by
the VB compiler in this situation. It would seem that VB treats it as an
implicit widening conversion in this case as 0 is the value that is
automatically assigned to an uninitialised enumeration variable. I've got a
work around for this issue right now but I would like to see this behaviour
(preferably) fixed or at least documented. This is especially the case
since there is no way to alter the compiler's decision (short of explicitly
passing variables/constants).

Regards,

Nick Hall

"Nick Hall" <ni***@aslan.nospam.co.uk> wrote in message
news:u2**************@TK2MSFTNGP15.phx.gbl...
I'm getting what I think is a bug in the way the VB compiler determines
the correct overloaded method to call. I have written a class to wrap
System.Configuaration.ConfigurationSettings with some type-safe methods -
for instance two methods are : -

Public Overloads Shared Function GetInt32(ByVal key As String, ByVal
defaultValue As Integer) As Integer
...
End Function

Public Overloads Shared Function GetInt32(ByVal key As String, ByVal style
As NumberStyles) As Long
...
End Function

(There are several other overloads but these are the two that are causing
me grief)

To me, the logical way to call this from my application class would be as
follows: -

Private Shared ReadOnly s_MyInteger As Integer =
ConfigurationSettings.GetInt32("IntegerKey", 0) 'This calls
GetInt32(String, NumberStyles)!!

However, when I do this, the compiler binds to the overload that takes a
NumberStyles parameter instead of the one that takes an integer! This
seems crazy to me as you would think the compiler would favour an exact
match over one that requires a conversion. Using CInt or the I suffix
does not alter this behaviour. The only work around is to declare a
constant or a variable with a suitable value and pass that instead: -

Private Const blankValue As Integer = 0
Private Shared ReadOnly s_MyInteger As Integer =
ConfigurationSettings.GetInt32("IntegerKey", blankValue) 'This calls
GetInt32(String, Integer) CORRECT!

Am I correct in thinking this is a compiler bug or am I missing some
subtlety in the resolution rules?

Regards,

Nick Hall

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Richard Hayden | last post by:
Hi, I have the following code for example: /**********************************/ #include <iostream> class C1 { public:
1
by: M Jared Finder | last post by:
What are the rules for method overload resolution when there are functions with a params argument? No mention of params is made in section 7.4.2 of the C# specification on MSDN (titled "Overload...
13
by: Vladimir Granitsky | last post by:
Hi guys, Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!? Am I right that C# compiler does wrong...
0
by: Eph0nk | last post by:
Hi, I get an overload resolution failed error (Overload resolution failed because no accessible 'New' can be called without a narrowing conversion), and I can't seem to find a lot of relevant...
2
by: Michi Henning | last post by:
Hi, the following code produces an error on the second-last line: Interface Left Sub op() End Interface Interface Right Sub op(ByVal i As Integer)
3
by: Christof Nordiek | last post by:
Given the following code Is there any way to call one of the Bar methods. using System; class Program { static void Main() { Foo<string, stringfoo = new Foo<string,string>();
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I have a strange situation with vb 2005 regarding option strict that looks like a compiler bug to me. Consider: Dim f1 As New Font("Arial", 8.25) Dim f2 As New Font("Arial", 8.25,...
2
by: xtrigger303 | last post by:
Hi to all, I was reading Mr. Alexandrescu's mojo article and I've a hard time understanding the following. Let's suppose I have: //code struct A {}; struct B : A {};
5
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar...
2
by: zbigniew | last post by:
Can someone explain me how overload resolution works in C++? For example if I have function void f(char, int); and I will call f('A', 3.1) or f(1.5, 3.1F) what would be the result? Thanks
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.