Q:

Would it be possible to define isShorter as a constexpr? If so, do so. If not, explain why not

0

Would it be possible to define isShorter as a constexpr? If so, do so. If not, explain why not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

No, a `constexpr` function may only contains statements that generate no actions at run time, but the member method `size()` must be called at run time, thus the function can not be a `constexpr` function.

<!---
A function like below can be `constexpr` function:

    constexpr bool isSameStr(const std::string &s1, const std::string &s2) {
      return &s1 == &s2;
    }

--->

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now