如何修改对象/类?

编程


寻求简单的建议

我正在重建我的 C++ 代码。
目前我有 QtCreator 构建默认类。
该类使用库处理“系统调用”。

我喜欢通过任一选项重建课程#
或系统命令的实际文本。

什么会是首选?

我认为传递一个选项 # 并让新的构造函数,而不是默认的构造函数
图片(切换)命令…

命令可以是“字符串列表”,而“开关”可能会变得太复杂……

我尝试过的:

传递选项 # – int ….

这是原始的默认构造函数

C++
MainWindow_Bluewtoothctl_Dialog::MainWindow_Bluewtoothctl_Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::MainWindow_Bluewtoothctl_Dialog)
{
    ui->setupUi(this);

#ifdef TRACE
...
#endif
    //..text = " Constructor...";
    // ui->textEdit->append(" Constructor...");
}

实际上
如何将 int 选项传递给“新构造函数”?

截至目前,这看起来是这样的:

C++
// origninal default constructor
MainWindow_Bluewtoothctl_Dialog(QWidget *parent = nullptr);

解决方案1

您不能在有默认值的参数后面添加没有默认值的参数。 所以如下:

C++
// illegal as command has no default
MainWindow_Bluewtoothctl_Dialog(QWidget *parent = nullptr, QTstring command)

// needs to be ...
MainWindow_Bluewtoothctl_Dialog(QWidget *parent, QTstring command)

// or
MainWindow_Bluewtoothctl_Dialog(QWidget *parent = nullptr, QTstring command = 'whatever a null QTstring is')

コメント

タイトルとURLをコピーしました