【发布时间】:2012-01-06 16:28:06
【问题描述】:
我有一个名为Modify 的函数。它是这样定义的:
Public Function Modify(Of SIMType As {New, DAOBase})(ByVal obj As DAOBase) As Boolean
你可以看到这个函数是通用的。它将 DAOBase 或 DAOBase 子类的对象作为参数。
在修改函数内部有一个这样的调用:
DAOToGP(obj)
这就是多态性发挥作用的地方。我为DAOBase 创建了四个左右的子类。我为这些类型中的每一种都写了一个DAOToGP()。因此,在Modify() 函数中,当它调用DAOToGP(obj) 时,应该会启动多态性,并且它应该调用DAOToGP() 的正确实现,具体取决于我传递给Modify() 的类型。
但是,我收到以下错误:
Error 20 Overload resolution failed because no accessible 'DAOToGP' can be called without a narrowing conversion:
'Public Shared Function DAOToGP(distributor As Distributors) As Microsoft.Dynamics.GP.Vendor': Argument matching parameter 'distributor' narrows from 'SierraLib.DAOBase' to 'IMS.Distributors'.
'Public Shared Function DAOToGP(product As Products) As Microsoft.Dynamics.GP.SalesItem': Argument matching parameter 'product' narrows from 'SierraLib.DAOBase' to 'IMS.Products'. C:\Users\dvargo.SIERRAWOWIRES\Documents\Visual Studio 2010\Projects\SIM\Dev_2\SIM\IMS\DVSIMLib\GP\GPSIMRunner\Runners\RunnerBase.vb 66 39 IMS
我在这里有点不知所措。我不确定为什么它无法确定要调用哪个函数。有什么想法吗?
【问题讨论】:
标签: .net vb.net polymorphism