Jac*_*ack 4 const clang constexpr c++11 c++14
clang ++给出以下警告(见下面的代码):
'constexpr'非静态成员函数在C++ 1y中不会隐式'const'; 添加'const'以避免行为发生变化
应该在哪里const添加?const constexpr size_t getSize() {再发一次警告:
返回类型的'const'类型限定符无效
码:
constexpr size_t getSize()
{
return sizeof(header);
}
Run Code Online (Sandbox Code Playgroud)
hap*_*ave 14
我相信它告诉你,从constC++ 1y开始,不能在对象上调用成员函数.
添加const后getSize()使其成为const成员函数:
constexpr size_t getsize() const { ... }
Run Code Online (Sandbox Code Playgroud)