使用 Windows 表单通信 C++ header 文件和源文件
Communicating C++ header file and source files with Windows Form
我正在构建一个 windows 表单应用程序,我需要这个 youtube header 和源文件 (for context) 来与 windows 表单中的按钮进行通信,我是几周前才开始的,对此我还很陌生,我的按钮已经有了这个 cpp 文件;
//i made this separate file because the windows form header file is flooded with system generated codes already
ButtonHandler.cpp
#include "pch.h"
#include "Main.h"
void MovieRentalSystem::Main::btn_clientAddReg_Click(System::Object^ sender, System::EventArgs^ e) {
//I need to call the linked list into here
DataList::DataList() { //(1) This is the first error I got
f_Data = NULL;
currentData = NULL;
temp = NULL;
}
}
所以我一直在按照提到的教程学习,这是我制作的header文件
LinkedList.h
#pragma once
ref class DataList {
private:
typedef struct fork { //(2) this is the second error I got
int data;
fork* nextData;
}* dataPointer;
dataPointer f_Data;
dataPointer currentData;
dataPointer temp;
public:
DataList();
void addFork(int addFork);
void delFork(int delFork);
void p_list();
};
错误:
(1) DataList::DataList() {
期待 ;
(2) struct
由于 Tomashu 的回答 here.
也许,我只是愚蠢地试图让他们交流,或者是否有更好的方法使用 System::Collections::Generic;
创建 LinkedList
或 List
?
首先正确包含头文件,你少了一个分号:
#include "LinkedList.h"
void MovieRentalSystem::Main::btn_clientAddReg_Click(System::Object^ sender, System::EventArgs^ e) {
//I need to call the linked list into here
// the call is also wrong, you want to create a variable here I guess
auto datalist = gcnew DataList() {
f_Data = NULL;
currentData = NULL;
temp = NULL;
}; // <-- is missing
}
第二个答案很直接,因为它告诉您标准 class 不能成为托管 class 的一部分。您只能在托管 classes:
中保存指针(和本机类型)
LinkedList.h
#pragma once
typedef struct fork { //(2) this is the second error I got
int data;
fork* nextData;
} dataFork;
ref class DataList {
private:
dataFork* f_Data;
dataFork* currentData;
dataFork* temp;
public:
DataList();
void addFork(int addFork);
void delFork(int delFork);
void p_list();
};
我正在构建一个 windows 表单应用程序,我需要这个 youtube header 和源文件 (for context) 来与 windows 表单中的按钮进行通信,我是几周前才开始的,对此我还很陌生,我的按钮已经有了这个 cpp 文件;
//i made this separate file because the windows form header file is flooded with system generated codes already
ButtonHandler.cpp
#include "pch.h"
#include "Main.h"
void MovieRentalSystem::Main::btn_clientAddReg_Click(System::Object^ sender, System::EventArgs^ e) {
//I need to call the linked list into here
DataList::DataList() { //(1) This is the first error I got
f_Data = NULL;
currentData = NULL;
temp = NULL;
}
}
所以我一直在按照提到的教程学习,这是我制作的header文件
LinkedList.h
#pragma once
ref class DataList {
private:
typedef struct fork { //(2) this is the second error I got
int data;
fork* nextData;
}* dataPointer;
dataPointer f_Data;
dataPointer currentData;
dataPointer temp;
public:
DataList();
void addFork(int addFork);
void delFork(int delFork);
void p_list();
};
错误:
(1) DataList::DataList() {
期待 ;
(2) struct
由于 Tomashu 的回答 here.
也许,我只是愚蠢地试图让他们交流,或者是否有更好的方法使用 System::Collections::Generic;
创建 LinkedList
或 List
?
首先正确包含头文件,你少了一个分号:
#include "LinkedList.h"
void MovieRentalSystem::Main::btn_clientAddReg_Click(System::Object^ sender, System::EventArgs^ e) {
//I need to call the linked list into here
// the call is also wrong, you want to create a variable here I guess
auto datalist = gcnew DataList() {
f_Data = NULL;
currentData = NULL;
temp = NULL;
}; // <-- is missing
}
第二个答案很直接,因为它告诉您标准 class 不能成为托管 class 的一部分。您只能在托管 classes:
中保存指针(和本机类型)LinkedList.h
#pragma once
typedef struct fork { //(2) this is the second error I got
int data;
fork* nextData;
} dataFork;
ref class DataList {
private:
dataFork* f_Data;
dataFork* currentData;
dataFork* temp;
public:
DataList();
void addFork(int addFork);
void delFork(int delFork);
void p_list();
};