【发布时间】:2010-11-07 04:34:21
【问题描述】:
我有以下与迭代使用 std::map 定义的关联字符串数组有关的问题。
-- snip --
class something
{
//...
private:
std::map<std::string, std::string> table;
//...
}
在构造函数中,我使用与字符串数据关联的字符串键对填充表。在其他地方我有一个方法toString,它返回一个字符串对象,其中包含表对象中包含的所有键和关联数据(作为键=数据格式)。
std::string something::toString()
{
std::map<std::string, std::string>::iterator iter;
std::string* strToReturn = new std::string("");
for (iter = table.begin(); iter != table.end(); iter++) {
strToReturn->append(iter->first());
strToReturn->append('=');
strToRetunr->append(iter->second());
//....
}
//...
}
当我尝试编译时,出现以下错误:
error: "error: no match for call to ‘(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >) ()’".
有人可以向我解释缺少什么,我做错了什么吗?
我只在hash_map 的情况下发现了一些关于类似问题的讨论,其中用户必须定义一个散列函数才能将hash_map 与std::string 对象一起使用。在我的情况下也可能是类似的东西吗?
【问题讨论】:
-
欢迎来到堆栈溢出,Crazybyte。很高兴我能提供帮助
标签: c++ dictionary iterator std stdmap