我想创建一个类SetHinzufuegen
的对象,并给它一个ListBox作为参数。应该以这种方式使用:我有另一个具有成员ListBox A
的类。我使用此SetHinzufuegen
作为参数创建类ListBox A
的对象,因此可以从此处编辑A
。
如何调用构造函数?
此外,我的类继承自带有#include <Dialog.h>
的Dialog并使用资源GUI.dll及其对话框DS_Window
。
GUI.h:
class SetHinzufuegen():public Dialog
{
public:
SetHinzufuegen(ListBox);
ListBox setWithVariablesListInputToWrite;
GUI.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++ - 调用在 header 中定义但在cpp中实现的构造函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21730689/