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