Guest User

Untitled

a guest
Aug 23rd, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.  
  5.     std::string gs;
  6.  
  7.     class Base {
  8.     public:
  9.         void add_string(const std::string &s)
  10.         {
  11.             gs += s + "\n";
  12.             //std::cout << s << "\n";
  13.         }
  14.         virtual void report();
  15.     };
  16.  
  17.     class : public Base {
  18.     public:
  19.         void report() override
  20.         {
  21.             add_string("report one");
  22.         }
  23.     } one;
  24.  
  25.     class: public Base {
  26.     public:
  27.         void report() override
  28.         {
  29.             add_string("report two");
  30.         }
  31.     } two;
  32.  
  33.     one.report();
  34.     two.report();
  35.     std::cout << gs;
  36.     return 0;
  37. }
  38.  
  39. -------------------------------------
  40.  
  41. test.cpp: In member function ‘void main()::Base::add_string(const string&):
  42. test.cpp:11:4: error: use of local variable with automatic storage from containing function
  43.     gs += s + "\n";
  44.     ^~
  45. test.cpp:5:14: note: ‘std::__cxx11::string gs’ declared here
  46.   std::string gs;
  47.               ^~
  48.  
Advertisement
Add Comment
Please, Sign In to add comment