hailler的个人主页

http://www.qtcn.org/bbs/u/183962  [收藏] [复制]

hailler

  • 0

    关注

  • 2

    粉丝

  • 21

    访客

  • 等级:新手上路
  • 总积分:25
  • 保密,2011-01-01

最后登录:2018-07-09

更多资料

日志

判断 Enum 里的QFlags 属性,不知道行不行。

2018-01-14 16:55
enum SomeEnum { Value1, Value2, Value3 };
Q_DECLARE_OPERATORS_FOR_FLAGS( QFlags <SomeEnum>)
// The previous line declares
// Q_DECL_CONSTEXPR QFlags<SomeValue> operator|(SomeValue,SomeValue) {...}

int someFunction( QFlags <SomeEnum> value) {
    switch (value) {
        case SomeEnum::Value1:
            return 1 ;
        case SomeEnum::Value2:
            return 2 ;
        case SomeEnum::Value1 | SomeEnum::Value3:
        // Only possible with C++11 and because QFlags operators are constexpr
        // Previously this line would call
        //        QFlags<SomeValue> operator|(SomeValue,SomeValue)
        // that would have thrown an error because only compiler constants
        // are allowed as case satement

            return 3 ;
        default :
            return 0 ;
    }
}
分类:默认分类|回复:0|浏览:170|全站可见|转载
 

Powered by phpwind v8.7 Certificate Copyright Time now is:07-19 13:18
©2005-2016 QTCN开发网 版权所有 Gzip disabled