模板参数可为浮点类型
Author: Haceau-ZoacCreated Jan 11, 2021Updated Jan 11, 2021
#include <iostream>
template <float a>
float qwq()
{
return a;
}
template <double foo>
double awa()
{
return foo;
}
int main(int argc, char* argv[])
{
std::cout << qwq<3.14F>() << '\n'
<< awa<6.28>() << '\n';
return 0;
}以上代码编译通过。
IDE:Microsoft Visual Studio Community 2019 16.9.0 Preview 2.0
编译器:msvc(启用 预览 - 最新 C++ 工作草案中的功能 (/std:c++latest))
Source: wuye9036/CppTemplateTutorial