简体   繁体   English

尝试为一个枚举重载operator + =时出现编译器错误

[英]Compiler errors when trying to overload operator+= for an enum

I'm having some problems trying to overload the += operator for an enum I've defined within a namespace. 我在尝试为我在命名空间中定义的枚举重载+ =运算符时遇到一些问题。 I shouldn't need to actually use the operator, however, a library I'm using (boost::icl) requires that the += operator is defined for the data I'm storing within the interval map. 我实际上不需要使用运算符,但是,我正在使用的库(boost :: icl)要求为我存储在间隔图中的数据定义+ =运算符。 Whenever I try to compile the code below, I get the following compiler error using Intel C++: 每当我尝试编译以下代码时,使用Intel C ++都会收到以下编译器错误:

error : enum "test::events" has no member "operator+="

Any suggestions? 有什么建议么?

test.h: test.h:

namespace test {

    enum events {
        SHUTIN = 0,
        ACTIVE,
        RECOMPLETE,
        CTI,
        RTP
    };

   events & events::operator+= (const events &rhs);

}; // end namespace test

test.cpp: TEST.CPP:

test::events & test::events::operator+= (const test::events &rhs) {
    return *this;
}

You can use a free function: 您可以使用免费功能:

events & operator+= (events &lhs, const events &rhs);

(tested with GCC 4.8, if Intel C++ rejects it I'd think it's a bug) (经过GCC 4.8的测试,如果Intel C ++拒绝它,我认为这是一个错误)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM