-1

I'm currently having a build issue in one on my class. the dev is done in Qt/c++

header.h

class Ui_DialogBoxProgress : public QDialog
{
    Q_OBJECT

public:
    explicit Ui_DialogBoxProgress(QWidget *parent = 0, Cache& cache);
    ~Ui_DialogBoxProgress();
    Cache& m_cache;

src.cpp

Ui_DialogBoxProgress::Ui_DialogBoxProgress(QWidget *parent, Cache& cache) :
    QDialog(parent),
    m_cache(cache),
    ui(new Ui::Ui_DialogBoxProgress)
{
    ui->setupUi(this);
    ...

Currently the error is :

header.h:21: error: missing default argument on parameter 'cache'
    explicit Ui_DialogBoxProgress(QWidget *parent = 0, Cache& cache);

and the call is done in the main.cpp like below :

DeleteProgress = new Ui_DialogBoxProgress(*this, *cache);
                                                          ^

Cache is a class defined below:

class Cache
{
public:
    Cache();
..

Any idea ? I already use this kind of method but the build never complain

Seb
  • 2,929
  • 4
  • 30
  • 73

1 Answers1

1

Once you define a default value for a function argument, every argument thereafter needs a default argument as well. This is a C++ rule, not just Qt. This will actually be difficult in your case because you're taking the second argument by non-const reference. Can you switch the order of function arguments, or will that require refactoring a lot of code? You can also take a Cache by pointer instead of reference; then you can set a default argument of nullptr for that argument.

This SO thread has a decent solution that you might want to take a look at.

Community
  • 1
  • 1
Carlton
  • 4,217
  • 2
  • 24
  • 40