c++ - 可变参数模板参数

标签 c++ templates variadic-templates

我的代码有一点问题。 我尝试创建一个带有可变参数的函数,但是当我编译它时,它失败了,我真的不明白为什么。 所以如果有人能帮助我......

这是我的功能:

查询集.hpp:

template <typename T>
class QuerySet
{
   template<typename U,typename ... Args>
   QuerySet& filter(const std::string& colum,Args ... args,const std::string& operation, const U& value);
   //...
}

template<typename T>
template<typename U,typename ... Args>
QuerySet<T>& QuerySet<T>::filter(const std::string& colum,Args ... args,const std::string& operation, const U& value)
{
     //some job
     return *this;
}

main.cpp 查询集查询集; queryset.filter(Perso::_master,Perso::_lvl,"gt",4);//第135行

注意: Perso::_master 和 Perso::_lvl 是一些 static const std::string;

错误:

g++ -g -std=c++0x -I"/my_path/cpp-ORM" -lmysqlcppconn   -o main.o -c main.cpp;
main.cpp: In function ‘int main(int, char**)’:
main.cpp:135:46: erreur: no matching function for call to ‘orm::QuerySet<Perso>::filter(const string&, const string&, const string&, int)’
main.cpp:135:46: note: candidate is:
/my_path/QuerySet.hpp:18:23: note: template<class U, class ... Args> orm::QuerySet<T>& orm::QuerySet::filter(const string&, Args ..., const string&, const U&) [with U = U, Args = {Args ...}, T = Perso, std::string = std::basic_string<char>]

信息: 我使用 gcc 版本 4.6.4 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04),但我尝试使用 gcc4.8,但出现错误。

最佳答案

可变参数包必须出现在函数签名的末尾,而不是中间。

为了更好地理解,请阅读以下内容: Variadic function template with pack expansion not in last parameter

关于c++ - 可变参数模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18851918/

相关文章:

c++ - 类型元组可以稍后解包吗?

c++ - boost 日志问题,版本 1.59

c++ - 错误 C2061 : syntax error : identifier 'istream'

c++ - 通过 ENUM 查找返回元组值(不同类型)的模板函数

c++ - 将集合论应用于 C++11 可变参数模板

c++ - 用于函数调用的带有可变参数模板的模板类型推导

c++ - 我的 C++ 列表迭代器是在改变位置,还是我做错了什么?

c++ - 如何将这样的位图复制到DC?

php - 模板系统范围问题

c++无法将父类指针作为类型定义对静态模板成员的引用