Re: Indexer on generic argument
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Mon, 25 Aug 2008 10:39:50 -0500
Pavel Minaev wrote:
On Aug 7, 6:47 pm, "Ben Voigt [C++ MVP]" <r...@xxxxxxxxxxxxx> wrote:
generic <typename TList, typename ItemType> where TList :
IList<ItemType>
ref class MyClass
{
public:
MyClass() {}
void Method(TList list1)
{
Console::Write("{0}, ", list1[0]); // error C2109 ??
IList<ItemType>^ list2 = list1;
This line shouldn't have worked -- list1 has stack semantics
(tracking reference), list2 is a tracking handle. You need an
address-of operator to make a handle from a reference.
It works because it's a generic declaration, not a template
declaration. Generic type parameters can only be instantiated with
handles for ref types - so, for a specific instantiation, TList would
be something like List<T>^, and not just plain List<T>.
Hmmm. Then the constraint line makes little sense. A tracking handle
doesn't implement an interface, the type of the referenced object does. I
realize this is connected to the .NET behavior of following different rules
when instantiating generics using ref types vs value types, and there
probably is no perfectly consistent syntax which expresses the behavior.
.
- References:
- Indexer on generic argument
- From: christian2 . schmidt
- Re: Indexer on generic argument
- From: Pavel Minaev
- Re: Indexer on generic argument
- From: Ben Voigt [C++ MVP]
- Re: Indexer on generic argument
- From: Pavel Minaev
- Indexer on generic argument
- Prev by Date: Re: Access denied fro GetShortPathName in Windows Vista
- Next by Date: Re: How to dllimport a dllexported class
- Previous by thread: Re: Indexer on generic argument
- Next by thread: Re: Initialize an array of classes?
- Index(es):
Relevant Pages
|