2
我遇到了模板特化的已删除模板函数的问题。下面的代码显示归结为MWE问题:删除的模板函数在gcc上工作,但不在叮当中
#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是针对[旧版本的C++ 11标准](https://stackoverflow.com/a/33258249/501250)编写的,它不允许对已删除函数进行专门化。是否有可用于此编译器的更新版本? – cdhowie