#include <map>
#include <string>
using namespace std;
class class1{
map<string, int> data;
friend bool func(const class1&);
public:
class1(){
data["test"] = 4;
}
};
int main(){
class1 sample;
func(sample);
}
bool func(const class1& sample){
if(sample.data["test"] == 4){
return true;
}else{
return false;
}
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY2xhc3MgY2xhc3MxewoJbWFwPHN0cmluZywgaW50PiBkYXRhOwoJZnJpZW5kIGJvb2wgZnVuYyhjb25zdCBjbGFzczEmKTsKcHVibGljOgoJY2xhc3MxKCl7CgkJZGF0YVsidGVzdCJdID0gNDsKCX0KfTsKCmludCBtYWluKCl7CgljbGFzczEgc2FtcGxlOwoJZnVuYyhzYW1wbGUpOwp9Cgpib29sIGZ1bmMoY29uc3QgY2xhc3MxJiBzYW1wbGUpewoJaWYoc2FtcGxlLmRhdGFbInRlc3QiXSA9PSA0KXsKCQlyZXR1cm4gdHJ1ZTsKCX1lbHNlewoJCXJldHVybiBmYWxzZTsKCX0KfQ==
prog.cpp: In function 'bool func(const class1&)':
prog.cpp:19:23: error: passing 'const std::map<std::basic_string<char>, int>' as 'this' argument discards qualifiers [-fpermissive]
if(sample.data["test"] == 4){
^
In file included from /usr/include/c++/5/map:61:0,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_map.h:494:7: note: in call to 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::basic_string<char>; _Tp = int; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::basic_string<char>]'
operator[](key_type&& __k)
^