【发布时间】:2015-04-30 00:52:17
【问题描述】:
基本上,我有一个二维向量:
std::vector<std::vector<double> > vect = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
我使用迭代器将此向量传递给函数:
template<typename Inverse>
void Diag(Inverse begin, Inverse end)
{
for(auto row : begin)
{
for(auto col : row)
{
}
}
}
我传递给这样的函数:Diag(std::begin(vect), std::end(vect))
但我一直抱怨没有匹配函数,即使我已经看到类似的基于范围的循环Here。
可以找到一个例子Here
编辑:
错误信息:
prog.cpp: In instantiation of 'void Diag(Inverse, Inverse) [with Inverse = __gnu_cxx::__normal_iterator<std::vector<double>*, std::vector<std::vector<double> > >]':
prog.cpp:30:39: required from here
prog.cpp:10:2: error: no matching function for call to 'begin(__gnu_cxx::__normal_iterator<std::vector<double>*, std::vector<std::vector<double> > >*&)'
for(auto row : &begin)
^
prog.cpp:10:2: note: candidates are:
In file included from /usr/include/c++/4.9/bits/basic_string.h:42:0,
from /usr/include/c++/4.9/string:52,
from /usr/include/c++/4.9/bits/locale_classes.h:40,
from /usr/include/c++/4.9/bits/ios_base.h:41,
from /usr/include/c++/4.9/ios:42,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from prog.cpp:1:
/usr/include/c++/4.9/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
begin(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.9/initializer_list:89:5: note: template argument deduction/substitution failed:
【问题讨论】:
-
谁投诉了?你老婆?
-
@thang 编译器,对不起哈哈!
-
发布来自编译器的确切错误消息。
-
@thang 更新了我的帖子 :)
-
你不想从头到尾吗? begin 不是一个集合,所以你不能使用 for(auto row : begin) 之类的集合循环