我想写一个函数,它会返回函数对,但在编译期间出现错误。如何从函数中返回对?
This is the whole file:
#include <iostream>
#include <map>
#include <utility>
using namespace std;
typedef pair<const string, const double> pr;
typedef map<const string,pr > mpr;
mpr mymap;
pr getvalue(const string s)
{
pr pValue;
mpr::iterator iter = mymap.find(s);
if(iter not_eq mymap.end())
{
pValue = (*iter).second;
}
return pValue;
}
int main()
{
getvalue("test");
}
错误消息:
在文件中包含从/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++ /4.4.7/bits/stl_algobase.h:66, from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4。 7/bits/char_traits.h:41, from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios :来自/ usr的/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40, 中的41, /lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40, f rom test8.cxx:1: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h :在成员函数'std :: pair,std :: allocator>中,const double> & std :: pair,std :: allocator>,const double> :: operator =(const std :: pair,std :: allocator> ,const double> &)': /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair。 h:68:错误:非静态const成员'const std :: basic_string,std :: allocator> std :: pair,std :: allocator>,const double> :: first',不能使用默认赋值运算符 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:68:error:non-static const member'const double std :: pair,std :: allocator>,const double> :: second',不能使用默认赋值操作符 test8.cxx:在函数'pr getvalue(std ::字符串)': test8.cxx:14:注意:合成方法'std :: pair,std :: allocator>,const double> & std :: pair,std :: allocator>,const double> :: operator =( const std :: pair,std :: allocator>,const double> &)'这里第一次需要
请帮帮我。
什么是错误? –
@LuchianGrigore错误已添加 – EmptyData
请避免修复您的问题,因为答案会尝试修复它,因为您使它们无效... – SirDarius