特殊化函数模板结果

Specialize function template result

本文关键字:结果 函数模板 特殊化      更新时间:2023-10-16

我对模板元编程很陌生,在这种方法中找不到我的思维错误:

template <typename T>
    typename T::ReturnType Query(const std::string& Str);
template <>
ResultTypeRowCount Query(const std::string& Str) { return this->queryRowCount(Str); }

ResultTypeRowCount实现一个名为ReturnType的公共类型定义

感谢您的阅读

应该是:

template <>
ResultTypeRowCount::ReturnType Query<ResultTypeRowCount>(const std::string& Str) { return this->queryRowCount(Str); }

专门化你的模板应该遵循以下模式:

template<typename T>
  void foo() {
  }
template<>
  void foo<int>() {
  }