Hello guys
.h
.cpp#ifndef A_H
#define A_H
#include <QObject>
#include <QList>
class A : public QObject
{
Q_OBJECT
private:
private:
void first();
void second();
void third ();
// and so on
void(A::*handlers[4])(void);
public:
A();
};
#endif // A_H
You see, this code gives me an error.#include "a.h"
void A::first()
{
}
void A::second()
{
}
void A::third()
{
}
A::A() : handlers {&A::first, &A::second, &A::third, 0}
{
//this is ugly
handlers[0] = &A::first;
handlers[1] = &A::second;
handlers[2] = &A::third;
//this would be nice
//handlers[4] = {&A::first,&A::second,&A::third,0};//in static this would work, because it would be like redeclaration, with the type speficier behind
}
I found out that this error does not happen when compiling the code using g++ with -std=c++11 in Cygwin.
Also, by searching on internet, I found out that this should work.
I want to initialize that array of pointers in the constructor, but it gives me this error:
Syntax error - Missing ; before }
Already placed parentheses, to look like this:
But it gives me a warning and an error:A::A() : handlers ({&A::first, &A::second, &A::third, 0})
Syntax error - missing ) before {
Warning - The elements of the array "A :: Handlers" are by default "initialized.
Is this a Qt problem?
Thanks
Bookmarks