fork download
  1. template<typename T>
  2. class out
  3. {
  4. T* _p;
  5. std::shared_ptr<T>& _sp;
  6. public:
  7. out(std::shared_ptr<T>& sp) : _p(nullptr) , _sp(sp) {}
  8. ~out() { _sp.reset(_p); }
  9. T** operator&() { _ASSERT(nullptr == _p); return &_p; }
  10. };
  11.  
  12. template <class T>
  13. out<T> make_out(std::shared_ptr<T> ptr)
  14. {
  15. return (out<T>(ptr));
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:10: error: 'shared_ptr' in namespace 'std' does not name a template type
     std::shared_ptr<T>& _sp;
          ^
prog.cpp:7:24: error: expected ')' before '<' token
     out(std::shared_ptr<T>& sp) : _p(nullptr) , _sp(sp) {}
                        ^
prog.cpp: In destructor 'out<T>::~out()':
prog.cpp:8:14: error: '_sp' was not declared in this scope
     ~out() { _sp.reset(_p); }
              ^
prog.cpp: At global scope:
prog.cpp:13:22: error: template declaration of 'out<T> make_out'
 out<T> make_out(std::shared_ptr<T> ptr)
                      ^
prog.cpp:13:17: error: 'shared_ptr' is not a member of 'std'
 out<T> make_out(std::shared_ptr<T> ptr)
                 ^
prog.cpp:13:34: error: expected primary-expression before '>' token
 out<T> make_out(std::shared_ptr<T> ptr)
                                  ^
prog.cpp:13:36: error: 'ptr' was not declared in this scope
 out<T> make_out(std::shared_ptr<T> ptr)
                                    ^
stdout
Standard output is empty