PDA

View Full Version : QFlags with std::initializer_list



TorAn
17th January 2016, 16:05
I am having a problem with QFlags class. Here is an pseudo-code example. I'll appreciate any comment/advise. Thanks.


class A {
...
public:
enum class SignalState {ENTRY, EXIT};
...
};

class B {
public:
Q_DECLARE_FLAGS(SignalUsage, A::SignalState)
B () : usage(A::SignalState::ENTRY | A::SignalState::EXIT) // fails
{
}
B (int) : usage(std::initializer_list<SignalUsage>({A::SignalState::ENTRY, A::SignalState::EXIT}) // fails
{
}
B (char) : usage(A::SignalState::ENTRY) // compiles
{
usage |= A::SignalState::EXIT; // compiles
}
private:
SignalUsage usage;
}

d_stranz
17th January 2016, 17:24
Try removing the "class" scoping on your definition of SignalState. It is possible that the Q_DECLARE_FLAGS() macro is not generating the correct code for this level of C++11 compliance. You can simulate scoping the old-fashioned way: SS_ENTRY, SS_EXIT.