I wonder what the rationale for this restriction is


Geoff Appleby discovers that a common C++ template idiom doesn't work with .Net generics. The code that doesn't work is this:

Public Class Class1(Of V As System.Web.Services.Protocols.SoapHttpClientProtocol)
  Inherits V

End Class

which is the .Net generics equivalent of this common C++ idiom:

template <class base>
class TDerived : public base
This is useful in all kinds of situations, as Christopher Diggins explains and, as Geoff says: "You don't know if V is NotIneritable, MustInherit, or whatever. It would surely fail at compile time if that happened" which is fine. Failing at compile time is great and means that this idiom is safe to use as you can't generate code that isn't legal; so what's the rationale behind the restriction?

Leave a comment