- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这本书的示例拷贝:
#include "stdafx.h"
#include<functional>
#include<iostream>
#include <vector>
#include <algorithm>
#include<iterator>
using namespace std;
template<typename input_iterator_tag, typename output_iterator_tag,
typename elem_type, typename comp>
output_iterator_tag
filter(input_iterator_tag first, output_iterator_tag last,
output_iterator_tag at, const elem_type &val, comp pred)
{
while ((first = find_if(first, last, bind2nd(pred, val))) != last)
{
cout << "found value: " << *first << endl;
*at++ = *first++;
}
return at;
}
int _tmain(int argc, _TCHAR* argv[])
{
const int elem_size = 8;
int ia[elem_size] = { 12, 8, 43, 0, 6, 21, 3, 7 };
vector<int>ivec(ia, ia + elem_size);
int ia2[elem_size];
vector<int>ivec2(elem_size);
cout << "filtering integer array for values less than 8\n";
filter(ia, ia + elem_size, ia2, elem_size, less<int>());
cout << "filtering integer vector for value greater than 8\n";
filter(ivec.begin(), ivec.end(), ivec2.begin(), elem_size, greater<int> ());//it's work ok
filter(ivec.begin(), ivec.end(), back_inserter(ivec2), elem_size, greater<int>());//compile error,no instance of function template "filter" matches
system("pause");
return 0;
}
为什么我用“back_inserter(ivec2)”代替书上说的“ivec2.begin()”,但它不能在visual studio中编译;
IntelliSense: no instance of function template "filter" matches the argument list argument types are: (std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, std::back_insert_iterator<std::vector<int, std::allocator<int>>>, const int, std::greater<int>)
谁能帮我改正,为什么?
最佳答案
看起来像是函数声明中的拼写错误。第二个参数 (last
) 应该是 input_iterator_tag
而不是 output_iterator_tag
,因为它应该匹配 first
迭代器,因为它直接与 first
进行比较。
template<typename input_iterator_tag, typename output_iterator_tag,
typename elem_type, typename comp>
output_iterator_tag
filter(input_iterator_tag first, input_iterator_tag last,
output_iterator_tag at, const elem_type &val, comp pred)
注意:它适用于您的第一个案例的原因是输入和输出类型相同。
关于c++ - “Essential C++” ch3.9用"back_inserter(ivec2)"替换"ivec2.begin()"编译不了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30586649/
package practicejava; public class Query { public static void main(String[] args) { char
因为我很困惑其中会存储什么。它是 ascii 值还是“z”,因为有些网站说它存储 ascii,有些网站说它存储“z”。链接说答案是“z”:http://cprogrammingworld4u.blog
这个问题在这里已经有了答案: mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expec
我无法将字符指针数组 s 的字符存储到字符数组 ch 中: int main() { char *s; s = malloc(1024 * sizeof(char));
我有这个代码: int main() { char ch[15]; cout<
在看《C++ Primer Plus 5th edition》时,看到了这样一段代码: cin.get(ch); ++ch; cout void print_type(cha
这行代码做了什么? char_to_ix = { ch:i for i,ch in enumerate(sorted(chars)) } ch:i 是什么意思? 最佳答案 这是@han solo 中提
这行代码做了什么? char_to_ix = { ch:i for i,ch in enumerate(sorted(chars)) } ch:i 是什么意思? 最佳答案 这是@han solo 中提
我在关注《C Primer Plus》这本书,遇到这样一段代码: // echo_eof.c -- repeats input to end of file. #include int main(v
这个问题在这里已经有了答案: Difference between int* a and int *a [duplicate] (2 个答案) Why is the asterisk before
我正在运行单个 goroutine 来处理与某些用户相关的消息 channel 。处理消息后,用户状态由 goroutine 更新并存储在数据库中。当对数据库的请求正在进行时,可以将许多消息发送到 c
这是完整的代码: s = 'life is short, stunt it!!?' from string import punctuation tbl = str.maketrans({ord(ch
在 C++ 中,(int) ch 是否等同于 int(ch)。 如果不是,有什么区别? 最佳答案 它们是同一个东西,也和(int)(ch)一样.在 C++ 中,通常首选使用命名转换来阐明您的意图: 使
我在 php 中使用 cURL。注意到每次启动 curl 案例时,人们总是把: $ch=curl_init(); “$ch”是什么意思? curl -F template_invoke_name='s
我正在编写与对齐相关的代码,如果给定的指针正确对齐,却没有标准的功能测试,这让我感到非常惊讶。 似乎互联网上的大多数代码都使用(long)ptr或 reinterpret_cast(ptr)测试对齐,
这个问题已经有答案了: C skipping one command of a function? [duplicate] (2 个回答) 已关闭 5 年前。 scanf("%c", &ch ) sc
然后我遇到了系统调用“write”,我尝试将“putchar”与“write”进行比较。现在,我对上面的代码行感到困惑。 最佳答案 putchar 是一个库函数。它调用 write 系统调用将字符写入
在 codechef 上用于更快输入输出的许多解决方案中,我遇到过这个表达式,但我无法理解它,因为我没有很多经验。 inline int scan( ) { int n=0; int ch=getch
这个问题在这里已经有了答案: What does space in scanf mean? [duplicate] (6 个答案) 关闭 7 年前。 像这样在scanf中加一个空格的目的是什么 sc
我的 spring-boot 应用程序中有以下 logback.xml: ... ...
我是一名优秀的程序员,十分优秀!