fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. public:
  7. Base(){};
  8. };
  9.  
  10. class HasA
  11. {
  12. Base *has;
  13. public:
  14. HasA(){
  15. has = &Base(); // error: taking address of temporary object
  16. // has = new Base();
  17. }
  18. };
  19.  
  20. int main()
  21. {
  22. HasA hs;
  23. return 0;
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor 'HasA::HasA()':
prog.cpp:15:18: error: taking address of temporary [-fpermissive]
      has = &Base(); // error: taking address of temporary object
                  ^
stdout
Standard output is empty