#include #include #include using std::cout; using std::endl; using std::string; //using namespace std; class Customer { private: string firstname; string lastname; int id; friend bool operator<(int i, Customer const& c); public: Customer(string first, string last, int ID);//constructor ~Customer(); //destructor string getName(); int getID() const{ return id; }; void SetName(string first, string second); bool operator<(Customer const& c) const; bool operator<(int i) const; }; bool operator<(int i, Customer const& c); Customer::Customer(string first, string last, int ID) { //cout << "Constructing the object with id " << ID << endl; firstname = first; lastname = last; id = ID; } Customer::~Customer() { //cout << "Destructing the object with id " << id << endl; } string Customer::getName() { return firstname + " " + lastname; } void Customer::SetName(string first, string last) { firstname = first; lastname = last; } bool Customer::operator<(Customer const& c) const { return id < c.getID(); } bool Customer::operator<(int i) const { return id < i; } bool operator<(int i, Customer const& c) { return i < c.id; } class Account : public Customer { private: string acctype; public: Account(string first, string last, int ID, string tp) : Customer(first, last, ID), acctype(tp) { cout << "Constructing Bank Account of type " << acctype << endl; } ~Account() { cout << "Distructing Bank Account of type " << acctype << endl; } }; template T max(T const& t1, T const& t2) { return t1 < t2 ? t2 : t1; } template class Latest { private: T latest; public: Latest(T const& start):latest(start) {}; void add(T const& t) { latest = max(latest, t); } T GetLatest() { return latest; } }; template<> class Latest { private: int latest; public: Latest(int const& start) :latest(start) {}; void add(Customer const& t) { latest = max(latest, t.getID()); } int GetLatest() { return latest; } }; int main() { //References int a = 3; cout << "Variable a is equal to " << a << endl; int& rA = a; rA = 5; cout << "Variable a is equal to " << a << endl; Customer c1("Kate", "Brown", 1); Customer & rC = c1; cout << "The name of the customer is " << rC.getName() << endl; //int & rB; References can not point to nowhere //Pointers int* pA = &a; *pA = 4; cout << "Variable a is equal to " << a << endl; int b = 10; pA = &b; (*pA)++; cout << "Variable b is equal to " << *pA << endl; Customer c2("James", "Bond", 7); Customer* pC = &c2; cout << "Customer's name is " << (*pC).getName() << endl; cout << "Customer's name is " << pC->getName() << endl; //int* pB = nullptr; //*pB = 3; //cout << "The pointed number is " << *pB << endl; return 0; }