【发布时间】:2019-03-24 23:36:10
【问题描述】:
#include <iostream>
class test
{
public:
constexpr void setX(int val);
private:
int x;
};
constexpr void test::setX(int val)
{
x = val;
std::cout << "x : " << x << '\n';
}
int main()
{
test obj;
obj.setX(5);
return 0;
}
这里的问题是,我无法在这个 constexpr 函数中执行用于调试的 I/O 操作。那么有什么方法可以在 constexpr 函数中进行 I/O 操作,还是这是 C++ 中的限制/行为?
【问题讨论】:
-
没有。
constexpr东西想在编译时计算。