为什么 gcc 告诉我我的模板不是模板?
Why does gcc tell me that my template is not a template?
>我有这样一段代码:
template<template<typename> class ContainerType,
typename ValueType,
typename ReturnType>
struct value_extractor
{
public:
static ReturnType extract(const ContainerType<ValueType>&);
};
template<template<typename> class ContainerType,
typename ValueType>
struct value_extractor<ContainerType, ValueType, std::shared_ptr<ValueType>>
{
static std::shared_ptr<ValueType> extract(const ContainerType<ValueType>& value)
{
return value;
}
};
它实质上是从模板类型中提取值。这段代码使用 clang 编译得很好,但使用 gcc 时我收到一个错误,说:
g++ test.cpp -lstdc++ -O2
In file included from di.hpp:1:0,
from test.cpp:2:
holders.hpp: In instantiation of ‘ReturnType di::holder<ContainerType, ValueType>::provide() const [with ReturnType = std::shared_ptr<int>; ContainerType = std::shared_ptr; ValueType = int]’:
di.hpp:35:105: required from ‘static ReturnType di::holder_selector::convert(const types_map&, ContainerType<ValueType>*) [with ReturnType = std::shared_ptr<int>; ContainerType = std::shared_ptr; ValueType = int; di::types_map = std::unordered_map<void (*)(), std::unique_ptr<di::base_holder> >]’
di.hpp:40:39: required from ‘T di::injector::provide() const [with T = std::shared_ptr<int>]’
test.cpp:14:63: required from here
holders.hpp:48:85: error: ‘di::value_extractor<ContainerType, ValueType, std::shared_ptr<_Up> >::extract(const ContainerType<ValueType>&) [with ContainerType = std::shared_ptr; ValueType = int]’ is not a template [-fpermissive]
alue_extractor<ContainerType, ValueType, ReturnType>::template extract(value_);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
如果我使用-fpermissive
标志,代码可以编译甚至工作,但显然会发出警告。 所以我的问题是:真的是我还是这是 gcc 的错误,如果是我编写不合格的代码,那么我应该如何解决它? 提前谢谢。
调用提取时不需要模板,愚蠢的错误。 感谢@songyuanyao
相关文章:
- 为什么 gcc 告诉我我的模板不是模板?
- 为什么我的 SFINAE 表达式不再适用于 GCC 8.2?
- 防止gcc破坏我的AVX2内部复制到REP MOVS
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- 为什么GCC在我的机器上创建额外的组装说明?
- 在CentOS 7上安装GCC 7.4.0不会更新我的LIBSTDC 版本
- 我的代码在使用GCC-MinGW时不再编译
- 如何从我的qt应用程序运行gcc编译器?
- 为什么尽管使用了 -isystem,但 clang 在我的标头上报告警告,而 gcc 没有报告警告?
- 为什么 gcc 和 clang 为我的程序编译为不同的"const"结果?
- 为什么我的makefile失败了,当我用gcc替换g ++时
- 如何在不将库源代码添加到我的项目中的情况下将库链接到 CodeBlocks 和 GCC 中的项目
- 为什么gcc抱怨我的循环
- GCC:我什么时候可以期望返回大型C++对象是有效的
- flens lapack:需要GNU GCC 4.7版或更高版本!我的mac有
- 在我的 Mac 上编译时,当我使用 "gcc" 而不是使用 clang++ 进行编译时出现此错误
- 当我的代码由 GCC 编译时内存泄漏
- Netbeans 8.1(适用于 C/C++)找不到我的编译器(gcc-6.0.0 开发版本)
- 来自 gcc 原子标头的对我的类静态字段错误的未定义引用
- 如何检查我的 gcc 版本