【问题标题】:Alias for "System::Collections::Generic::IList" in c++ clic++ cli中“System::Collections::Generic::IList”的别名
【发布时间】:2022-10-13 04:07:47
【问题描述】:

我正在使用 c++ cli。

每次为 IList 编写“System::Collections::Generic::IList”很困难,使代码冗长且难以阅读。

这里讨论了enter link description here

using IList = System::Collections::Generic::IList; // Didn't work.
typedef System::Collections::Generic::IList Ilist; // Didn't work also.

我怎样才能为它制作别名?

【问题讨论】:

  • typedef 工作正常。但这是泛型类型,您必须确定类型参数才能命名具体类型。所以,比如说,typedef System::Collections::Generic::IList<int> mylist;。您可以编写一个模板来提供类型参数,但它们在元数据中表现不佳。

标签: c++-cli alias


【解决方案1】:

我没有坐在编译器前,但我猜测 typedef 不起作用,因为 IList 不是该类型的全名:全名是 IList<some type>。你应该能够做到
typedef System::Collections::Generic::IList<String^> IStringList;

由于您似乎不想将 IList 的名称更改为其他名称,因此 using namespace System::Collections::Generic; 应该可以解决问题。

【讨论】:

    【解决方案2】:

    下面的代码编译。但这不是我要找的。 type in anle bravkets 可以是整数、字符串或任何类列表。但在某些情况下它是有效的。

    typedef System::Collections::Generic::IList<int>^ IintList1;
    using IintList2 = System::Collections::Generic::IList<int>^;
    
    IintList1 list1 = nullptr;
    list1->Add(1);
    IintList2 list2 = nullptr;
    list2->Add(2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多