`". cannot appear in constant expression
I am 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?
EDIT:
scope definition:
template <typename C, typename V, unsigned D>
class Region : public boost::array<Detail::Range<C>,D>
when Range
has variables min
and max
.
a source to share
Trying your code tells me the compiler has a problem with the part me[d].max < other[d].max
. So the dot problem was bogus. Instead, the compiler has a problem with the comparison operator. Simply repeating the comparison made the compiler error magically disappear:
if (me[i].min > other[i].min || other[i].max > me[i].max) {
return false;
}
a source to share
My guess is that this fails because the operator is []
not a valid operation on your variables me
, other
etc.
-
Have you overloaded the operator
[]
to your classRegion<>
? If so, does it return an object that actually has these membersmin
andmax
? - Does the overloaded operator return an object, an object by reference, or a pointer to an object? (In the latter case, you need to replace.
with->
.) -
If you haven't overloaded
[]
, thenme
,other
etc. would have to be declared as an array for your code to be valid.
a source to share
This probably doesn't work because you haven't defined the [] (unsigned) const operator. I would also suggest using std::size_t
or int
as your loop variable; very rarely seen unsigned
. However, since you are using an unsigned type, the logical choice would be to use std::size_t
. You can also try calling this-> operator [] (d) instead of me [d] as a sanity check, although what should work for you should be fine if your class implements the appropriate operator overloading.
a source to share