fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::string;
  5.  
  6. class Dog
  7. {
  8. protected:
  9. string m_name, m_breed, m_color;
  10. int m_age;
  11. public:
  12. Dog() : m_name("Fido"), m_breed("Corgi"), m_color("Black"), m_age(1) {}
  13. Dog(const Dog& d) { m_name = d.getName(); m_age = d.getAge(); }
  14. string getName() { return m_name; }
  15. int getAge() { return m_age; }
  16. };
  17.  
  18. int main()
  19. {
  20. }
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In copy constructor 'Dog::Dog(const Dog&)':
prog.cpp:13:46: error: passing 'const Dog' as 'this' argument of 'std::string Dog::getName()' discards qualifiers [-fpermissive]
       Dog(const Dog& d) { m_name = d.getName(); m_age = d.getAge(); }
                                              ^
prog.cpp:13:66: error: passing 'const Dog' as 'this' argument of 'int Dog::getAge()' discards qualifiers [-fpermissive]
       Dog(const Dog& d) { m_name = d.getName(); m_age = d.getAge(); }
                                                                  ^
stdout
Standard output is empty