473,387 Members | 1,548 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,387 software developers and data experts.

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 7978
A single is not a decimal, change one of them to match the other

Tom--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
..= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.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****@weightwatchers.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****@weightwatchers.com> wrote in message
news:eA**************@TK2MSFTNGP09.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.net> wrote in message
news:#3**************@TK2MSFTNGP09.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.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
.= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.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****@weightwatchers.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.2003FEB/vbcn7/html/vaconWideNarrowConversi
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.1033" 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********@email.msn.com> wrote in message
news:eh*************@TK2MSFTNGP10.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.asp
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****@weightwatchers.com> wrote in message
news:eA**************@TK2MSFTNGP09.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.net> wrote in message
news:#3**************@TK2MSFTNGP09.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.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
.= ..you are not trying hard enough.
==========================================
"Gang Zhang" <gz****@weightwatchers.com> wrote in message
news:%2****************@TK2MSFTNGP12.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
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...
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 {};
9
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.