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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it won’t. In C++11 there is a new keyword
constexprintroduced that helps generalize the notion of constant expressions. IfStringconstructor from"abc"is trivial enough then it could be declaredconstexpr; however such constructor probably has to allocate memory so it wouldn’t qualify.