【问题标题】:Managed array issue in C++/CLIC++/CLI 中的托管数组问题
【发布时间】:2012-06-16 07:54:46
【问题描述】:

使用 /clr 编译

array<Byte>^ byteArray =  gcnew array<Byte>(25);

为什么会出现这些编译器错误?

error C2065: 'array' : undeclared identifier
error C2065: 'gcnew' : undeclared identifier
error C2275: 'System::Byte' : illegal use of this type as an expression
error C3192: syntax error : '^' is not a prefix operator (did you mean '*'?)

我在一个类中调用这个方法

using namespace System;

__gc class MyClass

这感觉就像我在这里遗漏了一些非常基本的东西。即使这样也会导致错误:

array<Byte>^ byteArray;

array<Byte> * byteArray;

谢谢!!

【问题讨论】:

  • 确保您创建的项目是 C++/CLI 项目。
  • 也许,您的某个标题包含#pragma unmanaged 某处
  • 如果该类声明编译,那么您正在使用 /clr:oldsyntax。或者是VS2005之前的真正旧版本的VS。两者都不会解析 array

标签: arrays c++-cli clr managed managed-c++


【解决方案1】:

语法__gc class 曾在现已过时的托管C++ 中使用。在 C++/CLI 中,使用ref class

欲了解更多信息,请参阅the section Syntax changes in the Wikipedia article C++/CLI

【讨论】:

  • 别忘了 C++/CLI 本身也有一个更新的、有些不兼容的版本,称为 C++/CX。
  • @Arafangion 这不是 C++/CLI 的修订版,这是不同的:它与 .Net 没有任何关系。但它使用与 C++/CLI 相同(或非常相似)的语法。
猜你喜欢
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 2015-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多