【发布时间】:2016-09-30 05:21:22
【问题描述】:
下面是我正在尝试编译的代码(其中的 CPP 部分)
template<typename... T>
void SelectOperation::fetchNextRow(tuple<T...>& row) const
{
fetchColumn<0, decltype(row), T...>(row, nullptr);
}
template<int index, typename T, typename U>
void SelectOperation::fetchColumn(T& row) const
{
cout << typeid(row).name();
std::get<index>(row) = this->get<U>(index + 1);
}
template<int index, typename T, typename U, typename... V>
void SelectOperation::fetchColumn(T& row, void*) const
{
fetchColumn<index, T, U>(row);
fetchColumn<index + 1, T, V...>(row, nullptr); //Error at this statement
}
我得到的错误如下:
D:\workspaces\Calzone_Mayank\modules\Figgy\include\common/db/core/SelectOperation.h(149):
error C2783: 'void figgy::SelectOperation::fetchColumn(T &,void *) const': could not deduce
template argument for 'U'
D:\workspaces\Calzone_Mayank\modules\Figgy\include\common/db/core/SelectOperation.h(58):
note: see declaration of 'figgy::SelectOperation::fetchColumn'
D:\workspaces\Calzone_Mayank\modules\Figgy\include\common/db/core/SelectOperation.h(149):
error C2780: 'void figgy::SelectOperation::fetchColumn(T &) const': expects 1 arguments
- 2 provided
我无法理解为什么无法推断出argument for 'U'。为什么编译器无法确定它应该寻找哪个重载函数?
编辑
fetchNextRow 调用如下所示:
template<typename... T>
void SelectOperation::fetchAllRows(vector<tuple<T...>>& rows) const
{
while (next())
{
tuple<T...> row;
fetchNextRow<T...>(row);
rows.push_back(row);
}
}
与
vector<tuple<string, string, int>> rows;
SelectOperation o("users", {"name", "employee_id", "age"});
o.fetchAllRows<string, string, int>(rows);
【问题讨论】:
-
你怎么称呼
fetchNextRow?
标签: c++ c++11 compiler-errors variadic-templates