online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <memory> #include <queue> #include <string> //----------------------------------------------------------------------------- // do NOT use : using namespace std; //----------------------------------------------------------------------------- struct Packet { // moved to uint32_t for std::cout reasons. // uint8_t is displayed as(special) characters std::uint32_t index; std::uint32_t message; Packet() : index{ next_index() }, message{ index } { std::cout << "created packet : " << index << "\n"; } ~Packet() { std::cout << "destroyed packet : " << index << "\n"; } // small helper to not have to declare the static variable seperatly static std::uint8_t next_index() { static int counter; return counter++; } }; //----------------------------------------------------------------------------- class MyObject { public: void push_packet(); std::unique_ptr<Packet> pop_packet(); // this function returns a const reference (observation only) // of the packet at the front of the queue // while leaving the unique pointer on the queue (no moves needed // packet will still be owned by the queue) const Packet& front(); private: std::queue<std::unique_ptr<Packet>> m_queue; }; void MyObject::push_packet() { std::cout << "push_packet\n"; // push a packet m_queue.push(std::make_unique<Packet>()); std::cout << "push_packet done...\n"; } std::unique_ptr<Packet> MyObject::pop_packet() { std::unique_ptr<Packet> packet = std::move(m_queue.front()); m_queue.pop(); return packet; } const Packet& MyObject::front() { return *m_queue.front(); } //----------------------------------------------------------------------------- int main() { const std::size_t n_packets = 3ul; MyObject object; for (std::size_t n = 0; n < n_packets; ++n) { std::cout << "pushing packet\n"; object.push_packet(); } for (std::size_t n = 0; n < n_packets; ++n) { std::cout << "packet at front : "; std::cout << object.front().index << "\n"; std::cout << "popping front\n"; auto packet_ptr = object.pop_packet(); std::cout << "popped packet : " << packet_ptr->index << "\n"; } return 0; }

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