构造函数重载Bug? [英] Constructor Overloading Bug?

查看:57
本文介绍了构造函数重载Bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有谁知道,为什么在这个例子中没有调用第二个构造函数?

你能重现这个bug吗?

谢谢


克劳斯


Public Class Something


共享Sub Main()

Dim test1 As New Something(Cc,1)

Dim test2 As New Something(" String",2)
End Sub


Sub New(ByVal aChar As Char,ByVal aByte As Byte)

Console.WriteLine(" Char / Byte- Konstruktor")

End Sub


Sub New(ByVal aString As String,ByVal anInteger As Integer)

Console.WriteLine( " String / Integer-Konstruktor")

End Sub


结束班

解决方案

....实际上,它是第一个没有被调用的构造函数...


克劳斯


" ; Klaus L?ffelmann" < FO *********** @ loeffelmann.de> schrieb im Newsbeitrag

新闻:40 *********************** @ news.freenet.de ...



有谁知道,为什么在这个例子中没有调用第二个构造函数?
你能重现这个bug吗?
谢谢你/>
Klaus

Public Class Something

共享Sub Main()
Dim test1 As New Something(Cc,1)
Dim test2 As New Something(String,2)
End Sub

Sub New(ByVal aChar As Char,ByVal aByte as Byte)
Console.WriteLine (Char / Byte-Konstruktor)
End Sub

Sub New(ByVal aString As String,ByVal anInteger As Integer)
Console.WriteLine(" String / Integer) -Konstruktor")
End Sub

End Class



Klaus,
< blockquote class =post_quotes>有没有人知道,为什么第二个构造函数没有被调用这个例子?
你能重现这个bug吗?



如果强制常量1为字节(默认情况下它是一个整数),

将调用第一个构造函数。


Dim test1 As New Something(Cc,CByte(1))


Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。


嗨Klaus,


我不知道它是什么理论上的,但是他做得很好,

Dim test1 As New Something(Cc,CByte(1))


如果它首先尝试解析以查找它是否为整数而不是

将角色威胁为一个位置的字符串。


我希望这会有所帮助。


Cor

有没有人知道,为什么在这个例子中没有调用第二个构造函数?
你能重现这个bug吗?
谢谢



Hi,

does anybody know, why the second contructor isn''t called in this example?
Are you able to reproduce this bug?
Thanks

Klaus

Public Class Something

Shared Sub Main()
Dim test1 As New Something("C"c, 1)
Dim test2 As New Something("String", 2)
End Sub

Sub New(ByVal aChar As Char, ByVal aByte As Byte)
Console.WriteLine("Char/Byte-Konstruktor")
End Sub

Sub New(ByVal aString As String, ByVal anInteger As Integer)
Console.WriteLine("String/Integer-Konstruktor")
End Sub

End Class

解决方案

....actually, it is the first constructor, that is not being called...

Klaus

"Klaus L?ffelmann" <fo***********@loeffelmann.de> schrieb im Newsbeitrag
news:40***********************@news.freenet.de...

Hi,

does anybody know, why the second contructor isn''t called in this example?
Are you able to reproduce this bug?
Thanks

Klaus

Public Class Something

Shared Sub Main()
Dim test1 As New Something("C"c, 1)
Dim test2 As New Something("String", 2)
End Sub

Sub New(ByVal aChar As Char, ByVal aByte As Byte)
Console.WriteLine("Char/Byte-Konstruktor")
End Sub

Sub New(ByVal aString As String, ByVal anInteger As Integer)
Console.WriteLine("String/Integer-Konstruktor")
End Sub

End Class



Klaus,

does anybody know, why the second contructor isn''t called in this example?
Are you able to reproduce this bug?


If you force the constant 1 to be a Byte (it''s an Integer by default),
the first constructor will be called.

Dim test1 As New Something("C"c, CByte(1))

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Hi Klaus,

I do not know what is it theoretical, but this he does well,
Dim test1 As New Something("C"c, CByte(1))

Just if it first trys to resolve to find if it is an integer and than
threats the character as a one position string.

I hope this helps something.

Cor

does anybody know, why the second contructor isn''t called in this example?
Are you able to reproduce this bug?
Thanks



这篇关于构造函数重载Bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆