我在类中使用数组类型时出现C++/CLI数组类型不允许出现错误。首先,我在Visual Studio 2013中创建了一个控制台应用程序,并添加了一个新类“MainClass”。然后,我添加了一个新方法。事实是,我在主cpp文件的同一项目中使用了数组,没有任何类,没有问题,而且好像在this example中以相同的方式使用了数组。这是MainClass.h:
#pragma once
#using <System.dll>
#using <System.Security.dll>
#include <windows.h>
using namespace System;
using namespace System::Security;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::IO;
using namespace System::Collections::Generic;
ref class MainClass
{
public:
MainClass();
bool Verify(array<System::Byte> DataToVerify);
};
MainClass.cpp:
#include "MainClass.h"
#using <System.dll>
#using <System.Security.dll>
#include <windows.h>
using namespace System;
using namespace System::Security;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::IO;
using namespace System::Collections::Generic;
MainClass::MainClass()
{
}
bool MainClass::Verify(array<System::Byte> DataToVerify)
{
return false;
}
最佳答案
bool Verify(array<System::Byte> DataToVerify);
在C++/CLI中,知道何时使用^帽子非常重要。当您使用不当时,编译错误并非完全正确。数组是引用类型,当您将数组作为参数传递时,省略帽子在这里不是可选的。实际上,它从来都不是可选的,因为托管数组不是一次性的,所以在托管数组上的堆栈语义没有意义。使固定:
bool Verify(array<System::Byte>^ DataToVerify);
关于arrays - 在C++/CLI中的类中不允许使用数组吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28762681/