`.' cannot appear in a constant-expression

后端 未结 4 1042
悲哀的现实
悲哀的现实 2021-01-21 23:56

I\'m getting the following error:

`.\' cannot appear in a constant-expression

for this function (line 4):

    bool Covers(const         


        
相关标签:
4条回答
  • 2021-01-22 00:16

    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.

    0 讨论(0)
  • 2021-01-22 00:16

    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 讨论(0)
  • 2021-01-22 00:25

    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;
    }
    
    0 讨论(0)
  • 2021-01-22 00:28

    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.

    0 讨论(0)
提交回复
热议问题