开发者

`.' cannot appear in a constant-expression

I'm getting the following error:

`.' cannot appear in a constant-expression

for this function (line 4):

    bool Covers(const Region<C,V,D>& other) c开发者_JS百科onst {
        const Region& me = *this;
        for (unsigned d = 0; d < D; d++) {
            if (me[d].min > other[d].min || me[d].max < other[d].max) {
                return false;
            }
        }

can anyone explain the problem please?

EDIT:

the definition of Region is:

template <typename C, typename V, unsigned D>
class Region : public boost::array<Detail::Range<C>,D>

when Range has a min and max variables.


If stakx's answer is not sufficient, you may want to look into "min" and "max" variables. There may be some preprocessor definition, preventing the whole thing from working.

Try adding

#undef min   
#undef max  

just before your code, to see if the error stands.


Trying out your code tells me, that the compiler has a problem with the me[d].max < other[d].max part. So the problem with the dot was bogus. Instead the compiler has a problem with the comparison operator. Just reverting the comparison made the compiler error magically disappear:

if (me[i].min > other[i].min || other[i].max > me[i].max) {
       return false;
}


I assume this fails because the [] operator is not a valid operation on your variables me, other, etc.

  • Did you overload the [] operator on your Region<> class? If so, does it return an object which actually has these min and max members? — Does the overloaded operator return an object, an object by reference, or a pointer to an object? (In the last case, you'd need to replace . by ->.)

  • If you haven't overloaded [], then me, other etc. would have to be declared as an array for your code to be valid.


This is probably failing because you have not defined operator[](unsigned)const. I would also suggest that you use std::size_tor int as your loop variable; it is very uncommon to just see unsigned. Since you are using an unsigned type, though, the logical choice would be to use std::size_t. You could also try invoking this->operator[](d) instead of me[d] just as a sanity-check, although what you have should work fine assuming that your class implements the appropriate operator overload.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜