Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. class A
  5. {
  6.     int a;
  7.     static int f;
  8. public:
  9.     int get_a() {
  10.         return a;
  11.     }
  12.     A (const A &y) {
  13.         std::cin>>a;
  14.         a += y.get_a();
  15.     }
  16.     A () {
  17.         std::cin>>a;
  18.         f = 1;
  19.     }
  20.     ~A () {
  21.         if (f) {
  22.             std::cout<<a<<std::endl;
  23.             f = 0;
  24.         }
  25.     }
  26. };
  27.  
  28. int A::f=0;
  29.  
  30.  
  31.  
  32. Compilation error
  33. 000242.cpp: In copy constructor 'A::A(const A&)':
  34. 000242.cpp:14:22: error: passing 'const A' as 'this' argument discards qualifiers [-fpermissive]
  35.    14 |         a += y.get_a();
  36.       |                      ^
  37. 000242.cpp:9:9: note:   in call to 'int A::get_a()'
  38.     9 |     int get_a() {
  39.       |         ^~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement