jeudi 6 août 2015

Delegating class constructors in C++ using Qt

I try to delegate a class constructor in Qt 5.4.0 using C++. The problematic code looks as follows:

//.h
class A : public QObject
{

public:
  A(QObject *parent = 0) : A(10, parent) {};   <--COMPILER ERROR
  A(int x, QObject *parent = 0);
  ...
};

//.cpp
A::A(int x, QObject *parent) : QObject(parent)
{
  do_something();
}

The compiler claims that the element initialization 'A' is neither Basis nor Element. Isn't this supported? If so, what causes this error?

Aucun commentaire:

Enregistrer un commentaire