可变参数模板参数参数
variadic template parameter argument
我的代码有一点问题。我尝试创建一个带有可变参数的函数,但是当我编译它时,它失败了,我真的不明白为什么。所以如果有人可以帮助我...
这是我的函数:
QuerySet.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;
}
主.cpp 查询集查询集; queryset.filter(Perso::_master,Perso::_lvl,"gt",4);135路
注意: Perso::_master 和 Perso::_lvl 是一些静态常量 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,我有一个错误。
可变参数包必须出现在函数签名的末尾,而不是中间。
为了更好地理解,请阅读以下内容:包扩展不在最后一个参数中的可变参数函数模板
你的函数永远不能被调用,这是一个无法推导模板参数的上下文:
N3337, 14.8.2.1/1 [临时扣除调用]
模板参数推导是通过将每个函数模板参数类型(称为 P)与 调用的相应参数的类型(称为 A),如下所述。
[...]
对于出现在参数声明列表末尾的函数参数包, 将调用的每个剩余参数的类型 A 与 函数参数包。每次比较都推导出后续位置的模板参数 由函数参数包扩展的模板参数包。对于函数参数包 不出现在参数声明列表的末尾,参数包的类型是非推导的 上下文。
[...]
将参数包移动到函数参数列表的末尾。
您可以显式指定模板参数,但我认为这不是您想要的。例如:
q.filter<int, int, int>("oi", 1, 2, "oi", i);
相关文章:
- 在不传递参数数量且只有3个点的情况下,如何使用变差函数
- 如何使用可变参数模板强制转换每个变体类型
- 关于如何在具有单个参数的变体构造中选择替代方案?
- 调用参数排列不变函数 f(i++, i++)
- 参数归纳与标准::变体
- 模板化回调参数的逆变,如 C# 中的逆变
- 如何在没有参数包的情况下编写变差函数
- 通过具有嵌套类的工厂类获取多个变异类模板参数包
- 获取模板参数的成员变量值列表
- 保留短 lambda 用作函数的中间参数,使用 clang 格式保持不变
- 如何定义变体<x,y,z>提取模板参数的子类型
- 正确对齐内存模板,参数顺序不变
- 递归中不同参数类型的变元模板函数
- 通过函数指针传递给变差函数的参数会更改其值
- 提升预定义为带有参数的全局 lambda 的变体访问者
- 使用可变参数模板参数提升变体访问者
- boost ::变体 - 为什么模板参数比const字符串参数具有更高的优先级
- 将变参数包中的值加载到临时数组中
- 使用额外参数提升变体访客
- 正在将动态数组元素解析为参数?(变音符)