fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct Person
  5. {
  6. std::string name;
  7. std::string address;
  8.  
  9. Person (std::string n, std::string a)
  10. {
  11. name = n;
  12. address = a;
  13. }
  14. std::string get_name() { return name; }
  15. std::string get_address() { return address; }
  16. };
  17.  
  18.  
  19.  
  20. int main()
  21. {
  22. const Person p ("User", "UserAddr");
  23.  
  24. std::cout << p.get_name() << " " << p.get_address() << std::endl;
  25. }
  26.  
  27.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:24:33: error: passing 'const Person' as 'this' argument discards qualifiers [-fpermissive]
         std::cout << p.get_name() << " " << p.get_address() << std::endl;
                                 ^
prog.cpp:14:21: note:   in call to 'std::string Person::get_name()'
         std::string get_name() { return name; }
                     ^
prog.cpp:24:59: error: passing 'const Person' as 'this' argument discards qualifiers [-fpermissive]
         std::cout << p.get_name() << " " << p.get_address() << std::endl;
                                                           ^
prog.cpp:15:21: note:   in call to 'std::string Person::get_address()'
         std::string get_address() { return address; }
                     ^
stdout
Standard output is empty