C ++ / CLI中的类不允许使用数组?

时间:2022-09-01 23:25:28

I am getting a C++/CLI array type is not allowed here error when using array type in a class. First I have created a Console application in Visual Studio 2013 and added a new class "MainClass". Then I added a new method. The thing is that I used array in the same project in the main cpp file with no classes with no problems and it seems like it's being used the same way in this example. Here's MainClass.h:

在类中使用数组类型时,我不允许在此处获得C ++ / CLI数组类型错误。首先,我在Visual Studio 2013中创建了一个Console应用程序,并添加了一个新类“MainClass”。然后我添加了一个新方法。问题是我在主cpp文件中的同一个项目中使用了数组,没有没有问题的类,看起来它在这个例子中的使用方式相同。这是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;
}

1 个解决方案

#1


12  

    bool Verify(array<System::Byte> DataToVerify);

Knowing when to use the ^ hat is super-duper important in C++/CLI. And compile errors not exactly fantastic when you don't use it properly. Arrays are reference types, omitting the hat is not optional here when you pass the array as an argument. It is in fact never optional, stack semantics on managed arrays doesn't make sense since they are not disposable. Fix:

知道何时使用^ hat在C ++ / CLI中非常重要。如果你没有正确使用它,编译错误并不是很精彩。数组是引用类型,当您将数组作为参数传递时,省略帽子不是可选的。它实际上从不是可选的,托管数组上的堆栈语义没有意义,因为它们不是一次性的。固定:

    bool Verify(array<System::Byte>^ DataToVerify);

#1


12  

    bool Verify(array<System::Byte> DataToVerify);

Knowing when to use the ^ hat is super-duper important in C++/CLI. And compile errors not exactly fantastic when you don't use it properly. Arrays are reference types, omitting the hat is not optional here when you pass the array as an argument. It is in fact never optional, stack semantics on managed arrays doesn't make sense since they are not disposable. Fix:

知道何时使用^ hat在C ++ / CLI中非常重要。如果你没有正确使用它,编译错误并不是很精彩。数组是引用类型,当您将数组作为参数传递时,省略帽子不是可选的。它实际上从不是可选的,托管数组上的堆栈语义没有意义,因为它们不是一次性的。固定:

    bool Verify(array<System::Byte>^ DataToVerify);