online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include "Clock.h" int main() { std::cout.setf(std::ios::boolalpha); Clock c; appl(c); }
#ifndef CLOCK_H #define CLOCK_H #include <iosfwd> #include <cstring> #include <iostream> #include "IClock.h" #include "Counter.h" class Clock : public IClock { const char* name_; Counter hours_; Counter minutes_; Counter seconds_; public: Clock(const char* name, int hours = 0, int minutes = 0, int seconds = 0) : name_{std::strcpy(new char[std::strlen(name)+1], name)} , hours_{24} , minutes_{60, &hours_} , seconds_{60, &minutes_} { Set(hours, minutes, seconds); } ~Clock() { delete[] name_; } Clock(const Clock&) =delete; // copy c'tor Clock& operator=(const Clock&) =delete; // copy assignment Clock(Clock&&) =delete; // move c'tor Clock& operator=(Clock&&) =delete; // move assignment void Set(int hours, int minutes, int seconds) { hours_.SetValue(hours); minutes_.SetValue(minutes); seconds_.SetValue(seconds); } void TickUp(int seconds = 1) { seconds_.Count(seconds); } friend std::ostream& operator<<(std::ostream&, const Clock&); }; #endif
#include "Clock.h" #include <iostream> #include <iomanip> std::ostream& operator<<(std::ostream& lhs, const Clock& rhs) { std::ostream os{lhs.rdbuf()}; os.fill('0'); os << rhs.name_ << '=' << std::setw(2) << rhs.hours_.GetValue() << ':' << std::setw(2) << rhs.minutes_.GetValue() << ':' << std::setw(2) << rhs.seconds_.GetValue(); return lhs; }
#ifndef COUNTER_H #define COUNTER_H class Counter { private: int value_{}; const int max_value_{}; Counter* next_counter_{}; public: Counter() =delete; // Counter(const Counter&) =delete; // Counter& operator=(const Counter&) =delete; Counter(int max_value, Counter* next_counter = nullptr) : value_{0} , max_value_{max_value} , next_counter_{next_counter} {} void SetValue(int value) { value_ = value; } int GetValue() const { return value_; } void Count(int amount = 1); void Reset(); }; #endif
#include "Counter.h" void Counter::Count(int amount) { while (amount-- > 0) { if (++value_ == max_value_) { value_ = 0; if (next_counter_) { next_counter_->Count(1); } } } } void Counter::Reset() { value_ = 0; }
#include <iostream> #define SHOW(...)\ (void)(std::cout << __FILE__ << ':' << __LINE__ << '\t'\ << #__VA_ARGS__ << " --> " << (__VA_ARGS__)\ << std::endl) #include "IClock.h" void appl(IClock& c) { c.TickUp(); SHOW(c); c.TickUp(); SHOW(c); c.TickUp(); SHOW(c); c.Set(0, 0, 58); c.TickUp(); SHOW(c); c.TickUp(); SHOW(c); c.TickUp(); SHOW(c); c.TickUp(60); SHOW(c); c.TickUp(60); SHOW(c); }
#ifndef ICLOCK_H #define ICLOCK_H class IClock { TBD: Interface mit virtueller `Set` und `TickUp` Member Funktion }; #endif

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