c++ - 为什么我得到静态双变量的“变量的实例化......这里需要,但没有可用的定义”,而不是int?
问题描述
我正在编译这个程序:
template<int N> struct Foo {
static const double value;
};
int main() {
auto const& value = Foo<1>::value;
}
编译器输出头:
$ clang++ -std=c++17 ./main.cpp -o main
./main.cpp:6:31: warning: instantiation of variable 'Foo<1>::value' required here, but no definition is available [-Wundefined-var-template]
auto const& value = Foo<1>::value;
^
./main.cpp:2:23: note: forward declaration of template entity is here
static const double value;
^
./main.cpp:6:31: note: add an explicit instantiation declaration to suppress this warning if 'Foo<1>::value' is explicitly instantiated in another translation unit
auto const& value = Foo<1>::value;
神箭:https ://godbolt.org/z/V5-2Lh
如果我更改double
为int
,该警告就会消失。
在 C++ 规范中是否有这样做的原因,或者这个 LLVM 是否不一致?
解决方案
推荐阅读
- python - 从图像中提取和保存字符
- python - 如何从这个“元音食者”中删除字母?
- microsoft-graph-api - 使用 Graph API 向 Teams 中的特定用户发送消息
- python - 使用 Jetson.utils.cudaFont.OverlayText() 函数时,如何处理非典型英语的字母?
- azure-ad-b2c - 如果以前的配置文件抛出错误,验证配置文件仍会执行
- xml - 获取 XML 子节点并设置新的 ID 值
- authentication - 在 ASP.NET Core 中,是否可以在授权中使用枚举作为策略 RequireRole?
- sql - 将多条记录合并为一个人拥有的一条记录?
- webpack - WebPack 加载器 addDependency 是否将文件添加到包中?
- linux - Docker Swarm覆盖网络 - 容器无法通信