调用在标头中定义但在 cpp 中实现的构造函数

Call a constructor defined in header but implemented in cpp

本文关键字:实现 构造函数 cpp 定义 调用      更新时间:2023-10-16

我想创建一个类SetHinzufuegen的对象,并给它一个ListBox作为参数。它应该这样使用:我有另一个类,它有一个成员ListBox A。我使用此ListBox A作为参数创建了一个类 SetHinzufuegen 的对象,以便我可以从那里编辑A。如何调用构造函数?此外,我的类继承自带有#include <Dialog.h>的对话框,并使用资源 GUI.dll及其对话框DS_Window

图形用户界面:

class SetHinzufuegen():public Dialog
{
public:
    SetHinzufuegen(ListBox);
    ListBox setWithVariablesListInputToWrite;

图形.cpp:

SetHinzufuegen::SetHinzufuegen(setWithVariablesListInput):Dialog(DS_Window, "GUI");
{
    InputToEdit = setWithVariablesListInput;
    InitMsgMap();
}

我在构造函数的声明中遇到语法错误,因为我不理解这里的概念。

这样,在一个类中声明和实现,它可以工作:

class SetHinzufuegen : public Dialog
    {
    public:
        SetHinzufuegen(ListBox setWithVariablesListInput) : Dialog(DS_Window, "GUI")
        {
            inputToEdit = setWithVariablesListInput;
            InitMsgMap();
        }
        ListBox setWithVariablesListInputToWrite;

在这里,我调用构造函数

SetHinzufuegen SetDlg(setWithVariablesList);

我需要在标头声明或 cpp 实现中更改什么?

您缺少构造函数参数类型,并且有一个虚假;。你需要

SetHinzufuegen::SetHinzufuegen(ListBox setWithVariablesListInput) 
: Dialog(DS_Window, "GUI")
{
    InputToEdit = setWithVariablesListInput;
    InitMsgMap();
}

请注意,您不一定要复制ListBox。如果没有,请使用const引用参数。