C++ CLI - 错误 C2976:'std::tr1::array':MS C++ Express 2010 中的模板参数太少

c++ cli - error C2976: 'std::tr1::array' : too few template arguments in MS C++ express 2010

本文关键字:C++ 2010 参数 tr1 错误 CLI C2976 std MS array Express      更新时间:2023-10-16

我正在C++Express 2010中处理一个Windows窗体项目。对Form.h进行了一些更改,现在在编译程序时出现错误。请注意,编译器建议错误在主程序open gl test 2中,即#includes的形式。在我开发代码的过程中,所有程序都编译了好几天,然后昨晚更改了一些内容,现在我得到了错误。

open gl test 2中的主程序与我创建的任何其他基于表单的项目的主程序相同-我将其与check进行了比较[除了名称空间等的明显变化导致它是一个不同的项目]

// open gl test 2.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace opengltest2;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 
    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
} 

错误为:

1>open gl test 2.cpp(9): error C2976: 'std::tr1::array' : too few template arguments
1>          D:Program Files (x86)Microsoft Visual Studio 10.0VCincludearray(18) : see declaration of 'std::tr1::array'
1>open gl test 2.cpp(9): error C3699: '^' : cannot use this indirection on type 'std::tr1::array'
1>          compiler replacing '^' with '*' to continue parsing

编译器抱怨的行是

int main(array<System::String ^> ^args)

因此,错误不可能出现在编译器声称的地方——我在包含的文件中的代码中找不到错误——它们编译正确。我认为错误一定是形式.h,因为这就是我修改的导致这个错误的原因,但我看不到。我很确定我没有更改一些项目设置。

我没有包括form1.h的代码,因为它太长了。我想我要找的是人们寻找错误的经验。我可以使用什么策略来解决这个问题?如果我有头发要拔,我会被它包围。请帮我保存我不存在的头发。

编译器似乎混淆了托管数组类型和std库中的数组类型。这可能是因为在执行using namespace std时,理想情况下应该显式引用正确的命名空间(std::array或cli::array(,或者在不需要的情况下删除<array>的include。

请注意,常量大小的std::array不适合与命令行参数一起使用——无论如何,您都需要使用像cli::array这样的可变大小容器。