简体   繁体   中英

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. Whenever I try to compile the code below, I get the following compiler error using Intel C++:

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

Any suggestions?

test.h:

namespace test {

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

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

}; // end namespace test

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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