模板类中的模板函数

Template function in template class

本文关键字:函数      更新时间:2023-10-16

与此相关

无法编译以下内容,我真的不明白为什么。

Codebolt Code

片段在这里

#include <vector>
#include <string>

template<typename T>
class A
{
using func_type = bool(int const&);
template<func_type U, func_type X>
[[using gnu:cold]]void example(std::vector<std::string>&&);
};

template <typename T>
template <typename A<T>::func_type U, typename A<T>::func_type X>
void A<T>::example(std::vector<std::string>&&)
{
}

谢谢

如果您不想在类之外的任何地方使用该func_type。然后你应该把它改成

using func_type = bool(*)(int const&);

请记住,语法类似于为函数指针清空typedef