Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私が次のものを持っているとしましょう:
int i = 1; String str("abc");
str定数式と見なされますか?
str
多くの C++ の本から、定数式を整数型に評価する必要があるようです。
str は定数式と見なされますか?
いいえ、そうはなりません。C++11 ではconstexpr、定数式の概念を一般化するのに役立つ新しいキーワードが導入されています。Stringコンストラクター from"abc"が十分に自明である場合は、宣言できますconstexpr。ただし、そのようなコンストラクターはおそらくメモリを割り当てる必要があるため、資格がありません。
constexpr
String
"abc"