-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingFunctionPointers.cpp
More file actions
48 lines (36 loc) · 923 Bytes
/
UsingFunctionPointers.cpp
File metadata and controls
48 lines (36 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// FunctionPointers.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
bool match(string test) {
//return (test == "two");
return (test.size() == 3);
}
int countStrings(vector<string> &texts, bool (*match)(string test)) {
int tally = 0;
for(int i = 0; i < texts.size(); i++) {
if(match(texts[i])) {
tally++;
}
}
return tally;
}
int main2(int argc, _TCHAR* argv[])
{
vector<string> texts;
texts.push_back("one");
texts.push_back("two");
texts.push_back("three");
texts.push_back("two");
texts.push_back("four");
texts.push_back("two");
texts.push_back("three");
//cout << match("one") << end;
cout << count_if(texts.begin(), texts.end(), match) << endl;
cout << countStrings(texts, match) << endl;
return 0;
}