我有一种情况,我需要将编译时间常量存储在头文件中,并且我在使用它的类中执行此操作,因为我不想将常量暴露给包含此头文件的其他文件。(以及它依赖于另一个隐藏结构的事实)
像这样:
namespace ns {
class bla {
private:
struct internalStruct {
// ...
};
// I put it in the class as I don't want other files to be able to see this
constexpr const size_t compileConstant = sizeof(internalStruct) * 8;
};
}
问题是我得到一个
Constexpr is not valid here
错误。解决方案是添加static,但是我读到constexpr积分成员应该是内联的。
我该怎么办?