473,554 Members | 4,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overload Resolution error

Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible "myfunc" can
be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String': Argument
matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to Decimal?
Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!



Nov 19 '05 #1
5 7992
A single is not a decimal, change one of them to match the other

Tom--
=============== =============== ============
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.co m (www.45wallstreet.com)
= (803)-345-5001
=============== =============== ============
= If you are not making any mistakes
..= ..you are not trying hard enough.
=============== =============== ============
"Gang Zhang" <gz****@weightw atchers.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible "myfunc" can be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String': Argument matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to Decimal?
Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!



Nov 19 '05 #2
"Gang Zhang" <gz****@weightw atchers.com> schrieb
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible
"myfunc" can be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As
String': Argument matching parameter 'val' narrows from 'Double' to
'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String':
Argument matching parameter 'val' narrows from 'Double' to
'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to
Decimal? Why is the compiler trying to do

narrowing from Double to Decimal?


Enable Option Strict and you'll get the "real" error message.

Without Option Strict: I get a different message: "...narrwos from 'SINGLE'
to Decimal". Where does your "double" come from? Nevertheless, I don't see
the point: None of the signatures fit. Conversion from Single to Decimal is
a narrowing, not a widening conversion. So, not even implicit conversion
can be done. Therefore the error. Pass CDec(num1) (which might lead to a
runtime error) or Num1.ToString.
--
Armin

Nov 19 '05 #3
..Net doesn't convert anything to another datatype automaticly like it would
in VB6, that's why Ctype was added..

"Gang Zhang" <gz****@weightw atchers.com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes) and used the existing function instead of giving
a compiler error on attempting to do narrowing.
Gang

"Tom Vande Stouwe MCSD.net" <to**@conpro.ne t> wrote in message
news:#3******** ******@TK2MSFTN GP09.phx.gbl...
A single is not a decimal, change one of them to match the other

Tom--
=============== =============== ============
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.co m (www.45wallstreet.com)
= (803)-345-5001
=============== =============== ============
= If you are not making any mistakes
.= ..you are not trying hard enough.
=============== =============== ============
"Gang Zhang" <gz****@weightw atchers.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I have 2 overloaded functions as below:

myfunc(byval val as Decimal) as string
myfunc(byval val as String) as string

When calling the function with a single like:

dim num1 as single = ...

myfunc(num1)

I get an compiler error saying:
------------------------------------------
error BC30519: Overload resolution failed because no accessible
"myfunc"
can
be called without a narrowing conversion:

'Public Shared Overloads Function myfunc(val As Decimal) As String':
Argument matching parameter 'val' narrows from 'Double' to 'Decimal'.

'Public Shared Overloads Function myfunc(val As String) As String':

Argument
matching parameter 'val' narrows from 'Double' to 'String'.

------------------------------------------

What I don't understand is, should it be widening from Double to

Decimal? Why is the compiler trying to do

narrowing from Double to Decimal?

Thanks!





Nov 19 '05 #4
"Gang Zhang" <gz****@weightw atchers.com> schrieb
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes)
That's narrowing, not widening.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 FEB/vbcn7/html/vaconWideNarrow Conversi
ons.htm

(see hints in signature)

For example, the biggest positive value for Single is 3.4028235E+38
whereas it is only about 79E+28 for the Decimal data type.
and used the existing function instead of
giving a compiler error on attempting to do narrowing.


--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.10 33" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
tools -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.

Nov 19 '05 #5
Thanks all for the help!

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:eh******** *****@TK2MSFTNG P10.phx.gbl...
Gang,
But Single to Decimal is a narrowing not a widening conversion!

It not based on number of bytes as Single has a wider range then Decimal!
Although Decimal does has more precision. Single to Decimal would loose the range, hence its not allowed. Decimal to Single would loose the precision,
so its rounded and allowed.

See the conversion section of the Visual Basic .NET Language Specification

http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10.a sp
Specifically Narrowing Conversions:
http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10_4 .asp
Very specifically Narrowing Numeric Conversions:
http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfVBSpec10_4 _1.asp
Hope this helps
Jay

"Gang Zhang" <gz****@weightw atchers.com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
Thanks for the reply.

I understand a Single type is different from a Decimal type. And
I could have added another overloaded function that takes a Single
type input.

However, the question remains that the VB.NET compiler
should have done the automatical widening of Single(4 bytes) to a
Decimal( 16 bytes) and used the existing function instead of giving
a compiler error on attempting to do narrowing.
Gang

"Tom Vande Stouwe MCSD.net" <to**@conpro.ne t> wrote in message
news:#3******** ******@TK2MSFTN GP09.phx.gbl...
A single is not a decimal, change one of them to match the other

Tom--
=============== =============== ============
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.co m (www.45wallstreet.com)
= (803)-345-5001
=============== =============== ============
= If you are not making any mistakes
.= ..you are not trying hard enough.
=============== =============== ============
"Gang Zhang" <gz****@weightw atchers.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> Hi,
>
> I have 2 overloaded functions as below:
>
> myfunc(byval val as Decimal) as string
> myfunc(byval val as String) as string
>
> When calling the function with a single like:
>
> dim num1 as single = ...
>
> myfunc(num1)
>
> I get an compiler error saying:
> ------------------------------------------
> error BC30519: Overload resolution failed because no accessible "myfunc" can
> be called without a narrowing conversion:
>
>
>
> 'Public Shared Overloads Function myfunc(val As Decimal) As String':
> Argument matching parameter 'val' narrows from 'Double' to 'Decimal'. >
>
>
> 'Public Shared Overloads Function myfunc(val As String) As String':
Argument
> matching parameter 'val' narrows from 'Double' to 'String'.
>
> ------------------------------------------
>
>
>
> What I don't understand is, should it be widening from Double to

Decimal?
> Why is the compiler trying to do
>
> narrowing from Double to Decimal?
>
>
>
> Thanks!
>
>
>
>
>
>
>
>
>



Nov 19 '05 #6

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

Similar topics

4
2717
by: Arturo Cuebas | last post by:
The program below contains a compile error. Following the program you will find the typical fix then my idea for a library that facilitates a more elegant fix. #include <boost\bind.hpp> using namespace boost; struct C {
13
2708
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 overload resolution ? I've used parameters of type object and string here, just to illustrate the problem. Really I have a bit more deep inheritance...
0
2581
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 information by googling the web. Function GetFromXml(Id As String, Node As String) Dim NodeValue As String Dim xpathDoc As XPathDocument Dim...
2
1837
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
1520
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
3706
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, FontStyle.Bold) ' f1 is ok with option strict on or off ' f2 is ok with strict on, but with off I get an overload resolution failure The complete...
2
1856
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 {};
9
2190
by: sebastian | last post by:
I've simplified the situation quite a bit, but essentially I have something like this: struct foo { }; void bar( foo const & lhs, foo const & rhs )
5
3678
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 explicitly takes a pointer-to-member with no parameters, why is the lookup for the overloaded function not able to use the number of arguments to...
0
7620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3591
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3571
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.