Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cli Visual C++:将事件处理程序提取到.cpp文件 作为PHP开发人员,在做了大量的C++算法后,我决定开始学习Visual C++。刚开始工作,我就被一些基本的东西卡住了。我正在尝试将按钮单击事件从.h文件提取到.cpp文件_C++ Cli - Fatal编程技术网

C++ cli Visual C++:将事件处理程序提取到.cpp文件 作为PHP开发人员,在做了大量的C++算法后,我决定开始学习Visual C++。刚开始工作,我就被一些基本的东西卡住了。我正在尝试将按钮单击事件从.h文件提取到.cpp文件

C++ cli Visual C++:将事件处理程序提取到.cpp文件 作为PHP开发人员,在做了大量的C++算法后,我决定开始学习Visual C++。刚开始工作,我就被一些基本的东西卡住了。我正在尝试将按钮单击事件从.h文件提取到.cpp文件,c++-cli,C++ Cli,我的.h文件: #pragma once namespace Project1 { ... this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click); ... } 在我的.cpp文件中,我尝试这样做: #include "MyForm.h" using namespace System; using namespace System::Windows::Form

我的.h文件:

#pragma once

namespace Project1 {
...
    this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
...
}
在我的.cpp文件中,我尝试这样做:

#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
namespace Project1 {
    [STAThread]
    void main(array<String^>^ args)
    {

        void MyForm::button2_Click(System::Object^  sender, System::EventArgs^  e) {
            // definition
        }
...
}

它不起作用。它说Project1::MyForm没有按钮2\u Click。我错过了什么?

< P>标准学习语言警告:这不是C++,你写的是C++。C++/CLI是一种微软语言,旨在允许C++或其他.NET语言与标准C++接口。在这种情况下,C++/CLI可以提供两者之间的转换。如果你还在学习C++,请不要从C++开始。为了有效地在C++中编写,人们应该已经知道C++和C,然后还有一些东西要学习C++和CLI。如果你想学习C++,请坚持标准的非托管C++。在VisualStudio中,创建Win32 C++项目。如果您想学习托管代码,那么我将使用C

void main(array<String^>^ args)
{
    void MyForm::button2_Click(System::Object^  sender, System::EventArgs^  e) {
        // definition
    }
}
// MyForm.h
public ref class MyForm : System::Windows::Forms::Form
{
    // Lots of other stuff...
private:
    void button2_Click(System::Object^ sender, System::EventArgs^ e);
}
// MyForm.cpp
#include "MyForm.h"

void MyForm::button2_Click(System::Object^ sender, System::EventArgs^ e)
{
    // definition
}