Extending an Abstract class that uses a Generic Parameter

G

Guest

Hi,

I have a situation where I would like to extend an abstract (MustInherit)
class that uses a Generic parameter. The class declaration looks like this...

Public MustInherit Class BaseClass(Of T)

There is an Overridable method in this class that I would like to override.
There will be many classes in my program that need to derive from
BaseClass(Of T) but I only need one version of the Override method.

I'd like to do this...

Public MustInherit Class DerivedAbstractClass(of T) : Inherits BaseClass(of T)

I'd put my version of the Overrideable method here, and then use this class
as the parent of all my derived classes.

But the compiler says I cannot have a generic parameter in the Inherits part
of the declaration of my class.

Am I stuck with copying the same Override method into every class that
derives from BaseClass(Of T)?

Any suggestions?

Thanks.

BBM
 
M

Mattias Sjögren

But the compiler says I cannot have a generic parameter in the Inherits part
of the declaration of my class.

Can you post the exact error message you're getting and actual code
that will reproduce it? The following compiles fine here

MustInherit Class BaseClass(Of T)
End Class

MustInherit Class DerivedAbstractClass(Of T)
Inherits BaseClass(Of T)
End Class



Mattias
 
L

Linda Liu [MSFT]

Hi BBM,

I performed a test and didn't encounter a compilation error on the
following lines of code either.

Public MustInherit Class BaseClass(Of T)

End Class

public MustInherit Class DerivedAbstractClass(Of T)
Inherits BaseClass(Of T)

End Class

You may provide more actual code that reproduce the problem.
I'd put my version of the Overrideable method here, and then use this
class
as the parent of all my derived classes.

Why not implement the method in the BaseClass directly and then use the
BaseClass as the parent of all your derived classes?

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Mattias:

In preparing to reply to your request for more information, I stumbled upon
my mistake. The original class I was deriving from had a constraint on the
generic parameter and the compiler was complaining that the defintion of my
derived abstract class didn't comply with the constraint.

I added the constraint to my definition and it's working fine.

Thanks for helping me with this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top