Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main() {
- std::string gs;
- class Base {
- public:
- void add_string(const std::string &s)
- {
- gs += s + "\n";
- //std::cout << s << "\n";
- }
- virtual void report();
- };
- class : public Base {
- public:
- void report() override
- {
- add_string("report one");
- }
- } one;
- class: public Base {
- public:
- void report() override
- {
- add_string("report two");
- }
- } two;
- one.report();
- two.report();
- std::cout << gs;
- return 0;
- }
- -------------------------------------
- test.cpp: In member function ‘void main()::Base::add_string(const string&)’:
- test.cpp:11:4: error: use of local variable with automatic storage from containing function
- gs += s + "\n";
- ^~
- test.cpp:5:14: note: ‘std::__cxx11::string gs’ declared here
- std::string gs;
- ^~
Advertisement
Add Comment
Please, Sign In to add comment