online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <memory> class Base { public: virtual void hello() { std::cout << "hello" << std::endl; } }; class Derived : public Base { public: void hello() override { std::cout << "derived hello" << std::endl; } }; // return make_unique std::unique_ptr<Base> GetDerived() { std::cout << "GetDerived()" << std::endl; return std::unique_ptr<Base>(std::make_unique<Derived>()); // The below line equals to the above. //return std::make_unique<Derived>(); } // return auto ptr instead of unique_ptr std::unique_ptr<Base> GetDerived1() { std::cout << "GetDerived1() - Method 1" << std::endl; auto a = std::make_unique<Derived>(); return a; } #if 0 // return by casting lvalue std::unique_ptr<Base> GetDerived2() { std::cout << "GetDerived2() - Method 2" << std::endl; std::unique_ptr<Derived> a = std::make_unique<Derived>(); return std::unique_ptr<Base>(a); } #endif // return as move(lvalue) std::unique_ptr<Base> GetDerived3() { std::cout << "GetDerived3()" << std::endl; auto a = std::make_unique<Derived>(); return std::move(a); } // return auto ptr as lvalue std::unique_ptr<Base> GetDerived4() { std::cout << "GetDerived4()" << std::endl; auto a = std::make_unique<Base>(); return a; } // return auto ptr lvalue by casting std::unique_ptr<Base> GetDerived5() { std::cout << "GetDerived5()" << std::endl; auto a = std::make_unique<Base>(); return std::move(a); } int main() { std::unique_ptr<Base> gd = GetDerived(); std::unique_ptr<Base> gd1 = GetDerived1(); std::unique_ptr<Base> gd3 = GetDerived3(); std::unique_ptr<Base> gd4 = GetDerived4(); std::unique_ptr<Base> gd5 = GetDerived5(); return 1; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue