I have a generic items list class to create a more specific listing using it as base class, something like this..
ref class ItemBase { }
ref class ItemA : ItemBase { }
ref class ItemList abstract {
public:
virtual void add(ItemBase ^p);
}
ref class ItemListA : ItemList {
public:
virtual void add(ItemA ^p) override; // it doesn't works :(
}
I want to restric adding specific type of items in each class.
The accepted pattern for doing this is making the base class method
protected:Here is a better solution using generics. Note how we constrain the generic parameter
TtoItemBase, to enforce that this collection must only ne used withItemBaseor its subclasses.