Home >Backend Development >C++ >How Can I Get Items from a Covariant Collection with Indexing?
Retrieving Items from a Covariant and Indexed Collection
Covariant collections allow for retrieval of items through upcasting, but often lack index support. IEnumerable is an example of a covariant collection without indexing. However, there may be a need for a covariant collection that offers both indexing and upcasting.
The issue arises with the List class, which implements ICollection and has an Add method. Upcasting a List
If a covariant collection with index lookups is desired, alternatives can be considered:
The above is the detailed content of How Can I Get Items from a Covariant Collection with Indexing?. For more information, please follow other related articles on the PHP Chinese website!