constexpr and std::cout working on function but not in lambda
问题 Why constexpr does not work with std::cout , but works with printf ? #include <iostream> constexpr void f() { std::cout << ""; } //error constexpr void g() { printf(""); } //ok And why std::cout works with lambdas constexpr ? #include <iostream> int main () { auto h = []() constexpr { std::cout << ""; }; //ok } 回答1: Technically, it doesn't work with any of them. From [dcl.constexr]: For a constexpr function or constexpr constructor that is neither defaulted nor a template, if no argument