C++/CLI中对应托管C++ __typeof与__gc关键字的等效语法是什么
__typeof关键字替换方案
C++/CLI中直接使用typeid运算符等效替换旧托管C++的__typeof,二者作用完全一致,都是获取对应托管类型的System::Type^实例。
你提供的代码片段修改后如下:
private: System::ComponentModel::IContainer ^ components; private: void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); System::Resources::ResourceManager ^ resources = gcnew System::Resources::ResourceManager(typeid(USB::Form1)); // 其余原有逻辑保持不变 }
__gc关键字替换方案
旧托管C中用来标记托管数组的__gc[]语法,在C/CLI中统一替换为泛型模板array<T>^声明,不需要再加额外的__gc标记,你提供的三个代码片段修改后如下:
array<Char>^ chars = gcnew array<Char>(bytes->Length * 2); array<Char>^ hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; array<bool>^ ImageNumberUsed;
如果是多维托管数组,还可以声明为array<T, 维度数>^,比如二维int数组声明为array<int, 2>^ 数组名。
内容的提问来源于stack exchange,提问作者Gimmacus
相关产品推荐
相关产品推荐

