[問題] 關於 template instantiation 的問題
下面這兩行是正確的:
vector<int> v;
remove_if(v.begin(), v.end(), bind1st(less<int>(), 0));
如果把 less<int> 換成 less<const int> 或是 less<const int&> 都會 compile error
但如果是像下面這麼寫:
vector<int>::iterator iter = v.begin();
less<const int&>()(*iter, 0);
less<> 中的東西不論是 <int>, <const int>, <const int&> 都可以正常 compile,
請問這是什麼原因呢?
錯誤訊息如下:
In file included from /usr/include/c++/4.4/bits/stl_function.h:712,
from /usr/include/c++/4.4/functional:50,
from vec.cc:2:
/usr/include/c++/4.4/backward/binders.h: In instantiation of ‘
std::binder1st<std::less<const int&> >’:
vec.cc:11: instantiated from here
/usr/include/c++/4.4/backward/binders.h:117: error: ‘typename
_Operation::result_type std::binder1st<_Operation>::operator()(typename
_Operation::second_argument_type&) const [with _Operation =
std::less<const int&>]’ cannot be overloaded
/usr/include/c++/4.4/backward/binders.h:111: error: with ‘typename
_Operation::result_type std::binder1st<_Operation>::operator()(const
typename _Operation::second_argument_type&) const [with _Operation =
std::less<const int&>]’
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 139.175.68.252
推
11/24 01:13, , 1F
11/24 01:13, 1F
→
11/24 01:14, , 2F
11/24 01:14, 2F
→
11/24 01:14, , 3F
11/24 01:14, 3F
推
11/24 01:20, , 4F
11/24 01:20, 4F
→
11/24 01:25, , 5F
11/24 01:25, 5F
推
11/24 01:27, , 6F
11/24 01:27, 6F
→
11/24 01:28, , 7F
11/24 01:28, 7F
→
11/24 01:33, , 8F
11/24 01:33, 8F
推
11/24 01:34, , 9F
11/24 01:34, 9F
→
11/24 01:34, , 10F
11/24 01:34, 10F
→
11/24 01:35, , 11F
11/24 01:35, 11F
→
11/24 01:35, , 12F
11/24 01:35, 12F
推
11/24 01:49, , 13F
11/24 01:49, 13F
→
11/24 01:49, , 14F
11/24 01:49, 14F
→
11/24 01:50, , 15F
11/24 01:50, 15F
推
11/24 01:54, , 16F
11/24 01:54, 16F
推
11/24 07:35, , 17F
11/24 07:35, 17F
→
11/24 07:36, , 18F
11/24 07:36, 18F
→
11/24 07:41, , 19F
11/24 07:41, 19F
→
11/24 08:43, , 20F
11/24 08:43, 20F
→
11/25 10:49, , 21F
11/25 10:49, 21F