#ifndef PROPERTY_H #define PROPERTY_H #include #include #include #define BEGIN_ESTATE_NAMESPACE namespace ESTATE { using namespace std; #define END_ESTATE_NAMESPACE } BEGIN_ESTATE_NAMESPACE /** * In C++, we can put more than one class * in the same file */ class Test { public: // Member function of class Test // In this case, this is also the constructor for the class Test(int i) : _i(i) {} private: // Data member of class Test int _i; }; /** * Represents a property for sale * * As in Java, a C++ class contains methods * and attributes. However, these are called * member functions and data members */ class Property { public: /** * Example of a static method */ static int getCount(); /** * Class default constructor */ Property(); /** * Another class constructor. * Note that in C++, bool is a predefined type * so no need to include stdbool.h anymore * The last parameter illustrates the use of default * for arguments */ Property(int price, int lot_size, bool water=false); /** * Copy constrcutor * If ommitted, the default behavior will be * to copy data members one at the time */ Property(const Property& old) : _id(s_count++), _price(old._price), _lot_size(old._lot_size), _waterfront(old._waterfront), _test(1) { cout << toString() << " copy_constructed\n"; } /** * Class destructor. */ ~Property(); /** * Example of a simple member function * that modifies the value of a data member */ void adjustPrice(int new_price); /** * Example of function overloading * We have defined two member functions with the * same name but with different parameters * This is allowed and frequently used in C++ */ void adjustPrice(float new_price); /** * @return string representation of the object * Note that we are using the string class * instead of a char*. string is defined in the * standard C++ library */ string toString(); private: // This is also the default access mode static int s_count; int _id; int _price; int _lot_size; bool _waterfront; Test _test; }; END_ESTATE_NAMESPACE #endif