调用在标头中定义但在 cpp 中实现的构造函数
Call a constructor defined in header but implemented in cpp
我想创建一个类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
引用参数。
相关文章:
- 通过构造函数动态确定类实现
- 运算符+ 的规范实现涉及额外的移动构造函数
- 类中的数组变量C++导致"was not declared in this scope"实现文件的一个函数中错误,但在构造函数中不会导致错误
- 如何为具有私有成员的派生类实现移动构造函数
- 如何正确实现具有原始指针的类的复制构造函数?
- 复制构造函数和赋值运算符的值类实现
- 如何实现共享数据的复制构造函数
- 嵌套的模板结构构造函数实现
- 为什么<T> LLVM 中的预期为 Expect&&... 实现两个构造函数<T>?
- 在C++中正确实现复制构造函数
- 如何实现构造函数,使其仅接受使用 typeid 的输入迭代器?
- 如何将深拷贝构造函数实现到链表中?
- 如何在派生类上强制实现特定数据类型的构造函数?
- 如何实现内联显式类的构造函数?
- C++头/实现文件中的默认和重载构造函数?
- C++:默认构造函数实现
- std::sort 一个实现了移动构造函数的类
- 实现标记联合的移动构造函数
- 我如何实现从其基类获取变量的构造函数
- 实现构造函数时出现LNK2019错误