微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Windows 窗体通信 C++ 头文件和源文件

如何解决使用 Windows 窗体通信 C++ 头文件和源文件

我正在构建一个 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 创建 LinkedListList

解决方法

首先正确包含头文件,然后您缺少分号:

#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();
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。