fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class MyClass1
  5. {
  6. private:
  7. static const std::string MyConst; // = "SomeText";
  8. const std::string MyConst2; // = "SomeText";
  9. };
  10.  
  11. class MyClass2
  12. {
  13. private:
  14. static const std::string MyConst; // = "SomeText";
  15. static const std::string MyConst2; // = "SomeText";
  16. };
  17.  
  18. int main() {
  19. MyClass1 a1;
  20. MyClass1 a2(a1);
  21.  
  22. a1 = a2;
  23.  
  24. MyClass2 b1;
  25. MyClass2 b2(b1);
  26.  
  27. b1 = b2;
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:7: error: use of deleted function ‘MyClass1& MyClass1::operator=(const MyClass1&)’
  a1 = a2;
       ^~
prog.cpp:4:7: note: ‘MyClass1& MyClass1::operator=(const MyClass1&)’ is implicitly deleted because the default definition would be ill-formed:
 class MyClass1
       ^~~~~~~~
prog.cpp:4:7: error: passing ‘const string {aka const std::__cxx11::basic_string<char>}’ as ‘this’ argument discards qualifiers [-fpermissive]
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/basic_string.h:565:7: note:   in call to ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
       operator=(const basic_string& __str)
       ^~~~~~~~
stdout
Standard output is empty