我正在学习Andrew Koenig和Barbara Moo的Accelerated C++
(C ++ 98,而不是C ++ 11)中的向量。在这段代码中......
map<string, vector<int>> xref(istream& in, vector<string> find_words(const string&) = split) { ...
......块中定义了什么? xref
或find_words
?在我的调试器中,调用堆栈为:main() > xref() > split()
。 find_words
未在别处定义。
// find all the lines that refer to each word in the input
map<string, vector<int> > xref(istream& in, vector<string> find_words(const string&) = split) {
string line;
int line_number = 0;
map<string, vector<int>> ret;
// read the next line
while (getline(in, line)) {
++line_number;
// break the input line into words
vector<string> words = find_words(line);
// remember that each word occurs on the current line
for (vector<string>::const_iterator it = words.begin();
it != words.end(); ++it)
ret[*it].push_back(line_number);
}
return ret;
}
此外,split
看起来像这样:
vector<string> split(const string& s) { ... }
答案 0 :(得分:4)
map<string, vector<int>> xref(
istream& in,
vector<string> find_words(const string&) = split
) { /* ... */ }
这定义了名为xref
的函数。根据{{3}},xref
是一个函数:
作为参数:
istream
引用(istream& in
)vector<string> find_words(const string&) = split
)
string
常量引用(const string&
)vector<string>
split
(= split
)map<string, vector<int>>
答案 1 :(得分:0)
xref
是定义的函数,find_words
是其参数之一(以const string&
为参数并返回vector<string>
)和{{1的函数}是该参数的默认值。
答案 2 :(得分:0)
xref
正在代码块中定义,并返回字符串的映射和int的向量。它通过引用接受istream
的参数,该函数接受字符串常量引用并返回默认值被拆分的向量。