Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <vector>
- #include <string>
- class Employee
- {
- public:
- Employee(std::string const &name, unsigned age);
- std::string const &name() const;
- unsigned age() const;
- private:
- std::string mName;
- unsigned mAge;
- };
- Employee::Employee(std::string const &name, unsigned age)
- : mName(name)
- , mAge(age)
- {
- }
- std::string const &Employee::name() const
- {
- return mName;
- }
- unsigned Employee::age() const
- {
- return mAge;
- }
- std::ostream &operator <<(std::ostream &out, Employee const &employee)
- {
- return out << "Employee { name: " << employee.name() << ", age: " << employee.age() << " }";
- }
- int main()
- {
- std::vector<Employee> employees;
- employees.push_back(Employee("John", 23));
- employees.push_back(Employee("Anna", 22));
- copy(employees.begin(), employees.end(), std::ostream_iterator<Employee>(std::cout, "\n"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement