我很难找到为什么我会得到这个erorr。我正在使用可视工作室的C ++开发CLR UI窗体应用程序。
如果我尝试
private: int valueInSquare[9];
我收到错误说"托管类的成员不能是标准数组"
如果我将其更改为
private: array<int>^valueInSquare;
在尝试查看表单的头文件设计时,我得到了一个错误,
C ++ CodeDOM解析器错误:行:94,列:24 ---未知类型&#39;数组^&#39;。请确保引用包含此类型的程序集。如果此类型是开发项目的一部分,请确保已成功构建项目。
以下是代码的一部分,因为很多是通过在我的头文件中使用设计器预先生成的。
#pragma once
#include "Windows.h"
namespace MagicSquare {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MagicSquare
/// </summary>
public ref class MagicSquare : public System::Windows::Forms::Form
{
public:
MagicSquare(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MagicSquare()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::TextBox^ textBox7;
private: System::Windows::Forms::TextBox^ textBox8;
private: System::Windows::Forms::TextBox^ textBox9;
private: array<int>valueInSquare;
//private: int valueInSquare[9];
private: bool valueAlreadyUsed;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->textBox7 = (gcnew System::Windows::Forms::TextBox());
this->textBox8 = (gcnew System::Windows::Forms::TextBox());
this->textBox9 = (gcnew System::Windows::Forms::TextBox());
this->valueInSquare = gcnew array<int>(9);
for (int i = 0; i < 9; i++) {
valueInSquare[i] = 10;
}
this->SuspendLayout();
//
// label1
//
this->label1->BackColor = System::Drawing::Color::Blue;
this->label1->Location = System::Drawing::Point(65, 63);
this->label1->Name = "1";
this->label1->Size = System::Drawing::Size(65, 65);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
this->label1->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label2
//
this->label2->BackColor = System::Drawing::Color::Blue;
this->label2->Location = System::Drawing::Point(218, 63);
this->label2->Name = "2";
this->label2->Size = System::Drawing::Size(65, 65);
this->label2->TabIndex = 1;
this->label2->Text = L"label2";
this->label2->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
//
// label3
//
this->label3->BackColor = System::Drawing::Color::Blue;
this->label3->Location = System::Drawing::Point(383, 63);
this->label3->Name = "3";
this->label3->Size = System::Drawing::Size(65, 65);
this->label3->TabIndex = 2;
this->label3->Text = L"label3";
this->label3->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label4
//
this->label4->BackColor = System::Drawing::Color::Blue;
this->label4->Location = System::Drawing::Point(65, 153);
this->label4->Name = "4";
this->label4->Size = System::Drawing::Size(65, 65);
this->label4->TabIndex = 3;
this->label4->Text = L"label4";
this->label4->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label5
//
this->label5->BackColor = System::Drawing::Color::Blue;
this->label5->Location = System::Drawing::Point(218, 153);
this->label5->Name = "5";
this->label5->Size = System::Drawing::Size(65, 65);
this->label5->TabIndex = 4;
this->label5->Text = L"label5";
this->label5->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label6
//
this->label6->BackColor = System::Drawing::Color::Blue;
this->label6->Location = System::Drawing::Point(383, 153);
this->label6->Name = "6";
this->label6->Size = System::Drawing::Size(65, 65);
this->label6->TabIndex = 5;
this->label6->Text = L"label6";
this->label6->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label7
//
this->label7->BackColor = System::Drawing::Color::Blue;
this->label7->Location = System::Drawing::Point(65, 242);
this->label7->Name = "7";
this->label7->Size = System::Drawing::Size(65, 65);
this->label7->TabIndex = 6;
this->label7->Text = L"label7";
this->label7->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label8
//
this->label8->BackColor = System::Drawing::Color::Blue;
this->label8->Location = System::Drawing::Point(218, 242);
this->label8->Name = "8";
this->label8->Size = System::Drawing::Size(65, 65);
this->label8->TabIndex = 7;
this->label8->Text = L"label8";
this->label8->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// label9
//
this->label9->BackColor = System::Drawing::Color::Blue;
this->label9->Location = System::Drawing::Point(383, 242);
this->label9->Name = "9";
this->label9->Size = System::Drawing::Size(65, 65);
this->label9->TabIndex = 8;
this->label9->Text = L"label9";
this->label9->Click += gcnew System::EventHandler(this, &MagicSquare::labelOnClick);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(65, 84);
this->textBox1->Name = "1";
this->textBox1->Size = System::Drawing::Size(65, 20);
this->textBox1->TabIndex = 9;
this->textBox1->Visible = false;
this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(218, 84);
this->textBox2->Name = "2";
this->textBox2->Size = System::Drawing::Size(65, 20);
this->textBox2->TabIndex = 10;
this->textBox2->Visible = false;
this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(383, 84);
this->textBox3->Name = "3";
this->textBox3->Size = System::Drawing::Size(65, 20);
this->textBox3->TabIndex = 11;
this->textBox3->Visible = false;
this->textBox3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MagicSquare::MagicSquare::textBoxOnKeyPressed);
//
// textBox4
//
答案 0 :(得分:0)
标识符array
上可能存在名称冲突。请尝试使用其完全限定的名称cli::array
,以避免与std::array
以及该名称的其他用法产生歧义。