问题描述
我正在构建一个 windows 窗体应用程序,我需要这个 youtube 头文件和源文件 (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;
}
}
所以我一直在关注提到的教程,这是我制作的头文件
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.
也许,我只是因为试图与他们交流而变得愚蠢,或者有没有更好的方法来使用 ref
创建 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
}
第二个答案很简单,因为它告诉您标准类不能成为托管类的一部分。您只能在托管类中保存指针(和本机类型):
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();
};