문제

Lets say I have the following:

int i = 1;
String str("abc");

Would str be consider a constant expression?

From lots of C++ books, it seems a constant expression must be evaluated to an integral type.

도움이 되었습니까?

해결책

Would str be consider a constant expression?

No, it won't. In C++11 there is a new keyword constexpr introduced that helps generalize the notion of constant expressions. If String constructor from "abc" is trivial enough then it could be declared constexpr; however such constructor probably has to allocate memory so it wouldn't qualify.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top