【发布时间】:2017-07-24 15:29:40
【问题描述】:
我在使用已删除模板函数的模板特化时遇到问题。下面的代码显示了归结为 MWE 的问题:
#include <iostream>
#include <string>
template<typename T>
inline std::string typeToString() = delete;
template<>
inline std::string typeToString<float>()
{
return "float";
}
int main()
{
std::cout << typeToString<float>() << std::endl;
}
使用gcc 7 可以正常编译。但是,使用 Apple LLVM 8.0.0 我会收到以下错误消息:
clang test.cpp -std=c++1z
test.cpp:8:28: error: inline declaration of 'typeToString<float>' follows non-inline definition
inline std::string typeToString<float>()
^
test.cpp:8:28: note: previous definition is here
test.cpp:15:18: error: call to deleted function 'typeToString'
std::cout << typeToString<float>() << std::endl;
^~~~~~~~~~~~~~~~~~~
test.cpp:8:28: note: candidate function [with T = float] has been explicitly deleted
inline std::string typeToString<float>()
【问题讨论】:
-
也许 Apple LLVM 8.0.0 是针对 older version of the C++11 standard 编写的,它不允许专门化已删除的函数。您可以使用此编译器的更新版本吗?