E
Edward Diener
In C++ an overridden virtual function in a derived class must have the exact
same signature of the function which is overridden in the base class, except
for the return type which may return a pointer or reference to a derived
type of the base class's return type.
In .NET the overridden virtual function is similar, but an actual parameter
of the function can be a derived reference from the base class's reference
also.
This dichotomy can create a problem when using MC++ to override virtual
properties. In MC++ one can never override a virtual property by using a
derived reference type for the base class's reference type. In .NET one can
specify an overridden property which is a derived reference type from the
base class's reference type.
This dichotomy comes into play when creating a custom collection class in
MC++. The typical custom collection in other .NET languages overrides the
Item type in CollectionBase, not only to provide type-safe usage but to
creating a more specific type than an 'object' reference which the
collection editor in the Component Designer and Windows Form Designer will
understand to allow specific types to be added to a collection.
In MC++, however, it appears that the Item type must still be the 'object'
reference ( Object * in MC++ ) since it is impossible to override the
set_Item function with a different type than an Object * because of
paragraph 1 above. This means that because the get_Item and set_Item must
refer to the same type, the type must be Object * for an MC++ custom
collection class. Of course MC++ can still provide type-safe usage by not
allowing anything but the actual Item object, whatever it is, to be added,
inserted, and removed from the collection. However as far as the collection
editor in the Component Designer and Windows Form Designer is concerned, any
object is a possibility to be added to such a collection.
Is there a way around this difference between MC++ other .NET languages
other than writing one's collections in another .NET language and creating a
separate assembly just for the collection, or accepting the limitation of
MC++ as far as the collection editor is concerned ?
same signature of the function which is overridden in the base class, except
for the return type which may return a pointer or reference to a derived
type of the base class's return type.
In .NET the overridden virtual function is similar, but an actual parameter
of the function can be a derived reference from the base class's reference
also.
This dichotomy can create a problem when using MC++ to override virtual
properties. In MC++ one can never override a virtual property by using a
derived reference type for the base class's reference type. In .NET one can
specify an overridden property which is a derived reference type from the
base class's reference type.
This dichotomy comes into play when creating a custom collection class in
MC++. The typical custom collection in other .NET languages overrides the
Item type in CollectionBase, not only to provide type-safe usage but to
creating a more specific type than an 'object' reference which the
collection editor in the Component Designer and Windows Form Designer will
understand to allow specific types to be added to a collection.
In MC++, however, it appears that the Item type must still be the 'object'
reference ( Object * in MC++ ) since it is impossible to override the
set_Item function with a different type than an Object * because of
paragraph 1 above. This means that because the get_Item and set_Item must
refer to the same type, the type must be Object * for an MC++ custom
collection class. Of course MC++ can still provide type-safe usage by not
allowing anything but the actual Item object, whatever it is, to be added,
inserted, and removed from the collection. However as far as the collection
editor in the Component Designer and Windows Form Designer is concerned, any
object is a possibility to be added to such a collection.
Is there a way around this difference between MC++ other .NET languages
other than writing one's collections in another .NET language and creating a
separate assembly just for the collection, or accepting the limitation of
MC++ as far as the collection editor is concerned ?