0

Visual C ++プロジェクトのボタンをクリックすると、別のフォームが開き、Java JOptionPane.showInputDialogのように機能するようにしようとしていますが、希望どおりに表示されます。私はそれを開こうとしてForm21^form2=gcnew Form21(); form2->ShowDialog(); いますが、それが言うのは

1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'Form21' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2065: 'form2' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(253): error C2061: syntax error : identifier 'Form21'
1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2065: 'form2' : undeclared identifier
1>c:\users\steve\documents\visual studio 2010\projects\lesson 2\lesson 2\Form1.h(254): error C2227: left of '->ShowDialog' must point to class/struct/union/generic type
1>          type is ''unknown-type''

フォーム2はすべて問題ないはずですが、とにかくここにそのコードがあります

#pragma once

namespace Lesson2 {

    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 Form2
    /// </summary>
    public ref class Form2 : public System::Windows::Forms::Form
    {
    public:
        Form2(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form2()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::TextBox^  textBox2;
    protected: 

    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->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(12, 9);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(61, 13);
            this->label1->TabIndex = 0;
            this->label1->Text = L"Username :";
            this->label1->Click += gcnew System::EventHandler(this, &Form2::label1_Click);
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(81, 8);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(108, 20);
            this->textBox1->TabIndex = 1;
            this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form2::textBox1_TextChanged);
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(12, 54);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(59, 13);
            this->label2->TabIndex = 2;
            this->label2->Text = L"Password: ";
            // 
            // textBox2
            // 
            this->textBox2->Location = System::Drawing::Point(81, 47);
            this->textBox2->Name = L"textBox2";
            this->textBox2->Size = System::Drawing::Size(108, 20);
            this->textBox2->TabIndex = 3;
            // 
            // Form2
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(211, 88);
            this->Controls->Add(this->textBox2);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label1);
            this->DoubleBuffered = true;
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
            this->MaximizeBox = false;
            this->MinimizeBox = false;
            this->Name = L"Form2";
            this->Text = L"Create an account";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
             }
    private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             }
};
}

レッスン2と書いてあるのは知っていますが、それは私が自分自身に何かを教えていたからです。私はこのようなものを本当に簡単に拾います。これが発生する場合を除きます。誰かが何がうまくいかないのを見ますか?

4

1 に答える 1

1

Form21は別のファイルで宣言されている可能性が高いため、コンパイラはForm21タイプを見つけることができません。

Form1.hの先頭に、#include "Form21.h"(または、Form21のクラス宣言が異なる場合はそれを含むヘッダーファイルの名前)を追加します。

また、ヘッダーファイルとcppファイル(ヘッダーファイルにコードがあるようです)、前方宣言、およびc ++/cliに関するその他の基本的な事項についても読むことをお勧めします。

編集:あなたがあなたのForm2コードを投稿した後、エラーはその行Form21^form2=gcnew Form21();がであるはずであるということForm2^form2=gcnew Form2();です。あなたは宣言しましたがForm2、ではありませんForm21

幸運を!

于 2012-08-09T16:05:58.483 に答える