C++ 模板函数特化错误当特化在不同的头文件中

问题描述 投票:0回答:0

cnvt.h
标题中有:

template <typename t_to, typename t_from> std::optional<t_to> cnvt(t_from);

在标题

int.h
中,我们有:

#include "cnvt.h" 

template <>
std::optional<uint8_t> cnvt<uint8_t, const char *>(const char *) {
  // actual code replaced for simplicity
  return {};
}

事实上,

clang-tidy
报道

clang 报告“int.h:: Included header cvnt.h is not used directly (修复可用)包含的头文件 cvnt.h 不直接使用(修复 可用)

如果删除

#include "cnvt.h"
,它会报告

int.h:9:24:没有函数模板匹配函数模板专业化'cnvt'

我搜索了 StackOverflow,关于函数模板专业化的帖子没有帮助。

c++ function templates specialization
© www.soinside.com 2019 - 2024. All rights reserved.