0

I'm developing an application using Qt Widgets.

In my header files, I like to forward declare classes instead of including them. At the beginning of a header file I put forward declarations as follows:

class QFile;
class QDate;
class QTime;

And, there is a function declaration in the class as the following:

static bool addGoldTransaction(QFile *transactionsFile, Gold goldType, OperationType transactionType, float price, float amount, QDate date, QTime time);

When I try to compile, it gives an error like the following:

forward declaration of 'class QDate'
in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
In file included from moc_transaction.cpp:9:0:
error: initializing argument 6 of 'static bool addGoldTransaction(QFile*, Gold, OperationType, float, float, QDate, QTime)'

There is no error for forward declarations of other Qt-related classes.

Including the QDate header file solves the issue but I wonder:

  1. Why does the compiler complain only about QDate class while it doesn't complain about other classes? Is there anything special with QDate class related to this issue?
  2. How can I forward declare QDate class?
4

1 回答 1

0

传递 6 和 7 个类型的参数,QDateQTime通过引用QDate&QTime&或更好地通过 const 引用const QDate&const QTime&.

于 2017-12-23T01:50:43.153 回答