2

This compiles, but I'm wondering if it's unsafe.

In my header I forward declare this

class QStringList;
template<> class QList<QStringList>;

class MyClass {
     ...
     static void somethin(const QList<QStringList> &thelist);
}

then in my implementation i do this

#include <QStringList>
#include <QList>
#include "MyClass.h"
void MyClass::somethin(const QList<QStringLisT> &thelist) { ... }

Is this guaranteed to be safe no matter "what?"

Thanks

Boumbles
  • 2,473
  • 3
  • 24
  • 42

1 Answers1

0

somethin is declared to take a reference and defined to accept a pointer so that should not compile (unless it is an overload you have removed in the example.

As for the forward declaration of QList it should be fine since pointers and references such as in somethin only require forward declarations but beware that if the actual definition takes additional template arguments (possibly defaulted) then you must include those additional arguments in the forward declaration. That is one of the reasons why you should never forward declare types and functions in the standard library since they could have implementation defined additional parameters (template or otherwise) which can conflict.

John5342
  • 1,129
  • 1
  • 10
  • 13