fork(1) download
  1. #include <map>
  2. #include <string>
  3. using namespace std;
  4. class class1{
  5. map<string, int> data;
  6. friend bool func(const class1&);
  7. public:
  8. class1(){
  9. data["test"] = 4;
  10. }
  11. };
  12.  
  13. int main(){
  14. class1 sample;
  15. func(sample);
  16. }
  17.  
  18. bool func(const class1& sample){
  19. if(sample.data["test"] == 4){
  20. return true;
  21. }else{
  22. return false;
  23. }
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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)
       ^
stdout
Standard output is empty