online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include "Manager.h" static void PrintHierarchy(const Company::Manager * manager) { std::cout << manager->GetName() << std::endl; for (Company::TeamLead * teamLead : manager->GetSubordinates()) { std::cout << '\t' << teamLead->GetName() << std::endl; for (Company::Programmer * programmer : teamLead->GetSubordinates()) { std::cout << "\t\t" << programmer->GetName() << std::endl; } } } int main() { Company::Manager manager("Charles Manager", 0); Company::TeamLead teamLead_A("Alpha Lead", 1); Company::TeamLead teamLead_B("Bravo Lead", 2); Company::Programmer programmer_A0("John Alpha", 3); Company::Programmer programmer_A1("Jane Alpha", 4); Company::Programmer programmer_A2("Jeffrey Alpha", 5); Company::Programmer programmer_B0("Amos Bravo", 6); Company::Programmer programmer_B1("Ane Bravo", 7); Company::Programmer programmer_B2("Amy Bravo", 8); Company::Programmer programmer_B3("Arthur Bravo", 9); manager.Add(&teamLead_A); manager.Add(&teamLead_B); teamLead_A.Add(&programmer_A0); teamLead_A.Add(&programmer_A1); teamLead_A.Add(&programmer_A2); teamLead_B.Add(&programmer_B0); teamLead_B.Add(&programmer_B1); teamLead_B.Add(&programmer_B2); teamLead_B.Add(&programmer_B3); PrintHierarchy(&manager); return 0; }
#pragma once #include <vector> #include <string> #include "Employee.h" namespace Company { class Programmer : public Employee { private: std::vector<std::string> _languages; public: Programmer(std::string name, unsigned int id); void AddLanguage(std::string language); const std::vector<std::string> & GetLanguages() const; }; }
#include "Programmer.h" namespace Company { Programmer::Programmer(std::string name, unsigned int id) : Employee(name, id) { } void Programmer::AddLanguage(std::string language) { _languages.push_back(language); } const std::vector<std::string> & Programmer::GetLanguages() const { return _languages; } }
#pragma once #include "Leader.hpp" #include "Programmer.h" namespace Company { class TeamLead : public Leader<Programmer> { public: TeamLead(std::string name, unsigned int id); }; }
#include "TeamLead.h" namespace Company { TeamLead::TeamLead(std::string name, unsigned int id) : Leader<Programmer>(name, id) { } }
#pragma once #include "Leader.hpp" #include "TeamLead.h" namespace Company { class Manager : public Leader<TeamLead> { public: Manager(std::string name, unsigned int id); }; }
#include "Manager.h" namespace Company { Manager::Manager(std::string name, unsigned int id) : Leader<TeamLead>(name, id) { } }
#pragma once #include <string> namespace Company { class Employee { private: std::string _name; unsigned int _id; float _hoursWorked; public: Employee(std::string name, unsigned int id); const std::string & GetName() const; unsigned int GetId() const; float GetHoursWorked() const; void Work(float hours); }; }
#include "Employee.h" namespace Company { Employee::Employee(std::string name, unsigned int id) : _name(name), _id(id), _hoursWorked(0.0f) { } const std::string & Employee::GetName() const { return _name; } unsigned int Employee::GetId() const { return _id; } float Employee::GetHoursWorked() const { return _hoursWorked; } void Employee::Work(float hours) { _hoursWorked += hours; } }
#pragma once #include <vector> #include "Employee.h" namespace Company { template <class T> class Leader : public Employee { private: std::vector<T *> _subordinates; public: Leader(std::string name, unsigned int id) : Employee(name, id) { // from C++11 static_assert(std::is_base_of<Employee, T>::value, "type parameter must derive from Employee"); } void Add(T * subordinate) { _subordinates.push_back(subordinate); } const std::vector<T *> & GetSubordinates() const { return _subordinates; } }; }

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