views:

172

answers:

4

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) const {
        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.

+2  A: 
stakx
@stakx `[]` operator is overloaded (inherited from `boost::array`).
Amir Rachum
A: 

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.

Michael Aaron Safyan
+3  A: 

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.

Benoît
+1  A: 

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;
}
ablaeul