继承通用类 [英] Inherit Generic Class
本文介绍了继承通用类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通用父类为:
The generic parent Class is:
Option Strict Off
Option Explicit On
Imports System
Public MustInherit Class CNew_DataFile(Of T As Structure)
Private jRecord As Type
End Class
子类是:
The child class is:
Option Strict Off
Option Explicit On
Public Class CTest_ProdUnit
Inherits CNew_DataFile(Of RecordType)
Private Structure RecordType
Dim Index As Integer
Dim SubUnit As Integer ' reference to the sub unit index
<VBFixedString(150)> Dim Name As String
<VBFixedString(256)> Dim Description As String
<VBFixedString(8)> Dim Abbr As String ' abbreviation
Dim InvoiceUnitType As Short ' the unit type printed on the invoice
Dim UnitType As Short ' the type of unit (base, product, or both)
Dim Activity As Short
Dim SubUnitQty As Single
Dim MeasSystem As Short ' the measurement system
End Structure
End Class
Visual Studio报告以下错误:''CTest_ProdUnit"不能从类"CNew_DataFile(Of RecordType)"继承,因为它会将类型"RecordType"的访问扩展到名称空间"WareHouseMngtSys". >
显然,该项目的名称是WareHouseMngtSys.
Visual Studio reports the following error: " ''CTest_ProdUnit'' cannot inherit from class ''CNew_DataFile(Of RecordType)'' because it expands the access of type ''RecordType'' to namespace ''WareHouseMngtSys''. "
Obviously, the name of the project is WareHouseMngtSys.
推荐答案
好的,这很明显.
您的RecordType结构在CTest_ProdUnit类内部被声明为私有.这意味着该结构仅在CNew_DataFile类内部可见.
但是,由于它继承自CNew_DataFile( Of RecordType ),因此RecordType可见性与Public accessibility修饰符冲突.
解决方案很简单.在其所在的类的外部声明RecordType并将其公开.
OK, it''s fairly obvious.
Your RecordType structure is declared private inside the CTest_ProdUnit class. That means the struct will be visible only inside the CNew_DataFile class.
But, since it''s inheriting from CNew_DataFile(Of RecordType) the RecordType visibility is in conflict with Public accessibility modifier.
The solution is easy. Declare RecordType outside the Class it''s sitting in and make it Public.
这篇关于继承通用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文