/tags/rel-1-3-26/SWIG/Examples/java/extend/example.h
C++ Header | 56 lines | 48 code | 7 blank | 1 comment | 2 complexity | 68fa66396bc2597b161f04b9a2d81849 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1/* File : example.h */ 2 3#include <cstdio> 4#include <iostream> 5#include <vector> 6#include <string> 7#include <cmath> 8 9class Employee { 10private: 11 std::string name; 12public: 13 Employee(const char* n): name(n) {} 14 virtual std::string getTitle() { return getPosition() + " " + getName(); } 15 virtual std::string getName() { return name; } 16 virtual std::string getPosition() const { return "Employee"; } 17 virtual ~Employee() { printf("~Employee() @ %p\n", this); } 18}; 19 20 21class Manager: public Employee { 22public: 23 Manager(const char* n): Employee(n) {} 24 virtual std::string getPosition() const { return "Manager"; } 25}; 26 27 28class EmployeeList { 29 std::vector<Employee*> list; 30public: 31 EmployeeList() { 32 list.push_back(new Employee("Bob")); 33 list.push_back(new Employee("Jane")); 34 list.push_back(new Manager("Ted")); 35 } 36 void addEmployee(Employee *p) { 37 list.push_back(p); 38 std::cout << "New employee added. Current employees are:" << std::endl; 39 std::vector<Employee*>::iterator i; 40 for (i=list.begin(); i!=list.end(); i++) { 41 std::cout << " " << (*i)->getTitle() << std::endl; 42 } 43 } 44 const Employee *get_item(int i) { 45 return list[i]; 46 } 47 ~EmployeeList() { 48 std::vector<Employee*>::iterator i; 49 std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; 50 for (i=list.begin(); i!=list.end(); i++) { 51 delete *i; 52 } 53 std::cout << "~EmployeeList empty." << std::endl; 54 } 55}; 56